在引导转盘内分为两列的两个自定义POST类型

时间:2017-05-11 作者:Rafael Dantas

我试图使用引导旋转木马在我的页面中显示一些自定义帖子,如下图所示

enter image description here

但现在,我的旋转木马只显示了两次相同的帖子,如下图所示enter image description here

这是我的密码:

            <?php $args = array(\'post_type\' => \'cases\', \'order\' => \'DESC\', \'orderby\' => \'date\', \'posts_per_page\' => \'-1\');
            $the_query = new WP_Query( $args );

            if( $the_query->have_posts() ):?>   
            <?php  $index = 0; ?>

                <div id="myCarousel" class="carousel slide" data-ride="carousel">
                  <!-- Indicators -->
                  <ol class="carousel-indicators">
                    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                    <li data-target="#myCarousel" data-slide-to="1"></li>
                  </ol>

                  <!-- Wrapper for slides -->
                <article class="container">
                    <div class="row">
                        <div class="carousel-inner">
                            <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
                                <div class="item<?php if ($index == 1) { echo \' active\'; } ?>">
                                    <div class="col-md-6">
                                        <?php  
                                            $imagem_personalizada = get_field(\'capa_da_pagina_do_case\');
                                            $thumb_capa = wp_get_attachment_image_src($imagem_personalizada, \'capaIdeia\');
                                        ?>
                                        <a href="<?php the_permalink();  ?>" style="text-decoration: none;">
                                            <br>
                                            <div id="secao-titulo-ideia-single" class="nopadding">
                                                <img  class="img-responsive center-block" src="<?php echo $thumb_capa[0]; ?>" alt="Thumb Post" width="100%">
                                                <h2 class="brandonregular titulo-ideia-single text-center"> <?php  the_field(\'titulo_do_case\'); ?> </h2>
                                            </div>
                                        </a>
                                    </div>
                                    <div class="col-md-6">
                                        <a href="<?php the_permalink();  ?>" style="text-decoration: none;">
                                            <div class="nopadding">
                                                <img  class="img-responsive center-block" src="<?php echo $thumb_capa[0]; ?>" alt="Thumb Post" width="100%">
                                                <h2 class="brandonregular"> <?php  the_field(\'titulo_do_case\'); ?> </h2>
                                            </div>
                                        </a>
                                    </div>
                                </div>
                            <?php $index++; ?>
                            <?php endwhile; ?>
                        </div>
                    </div>
                </article>
                </div>
            <?php endif; ?>
            <?php wp_reset_query(); wp_reset_postdata(); ?>
我不知道为什么会这样,我尝试了很多不同的方法,但我找不到解决这个问题的方法。

我做错了什么?

1 个回复
SO网友:Picard

你可以试试这样的。

想法是在循环中检查项目是偶数还是奇数,对于奇数项目,打开两个项目的幻灯片(显示开头的HTML),对于偶数,关闭它。

我还没有测试过,但想法是这样的:

<article class="container">
    <div class="row">
        <div class="carousel-inner">
            <?php 
                $cnt = 1;
                while( $the_query->have_posts() ) : $the_query->the_post(); ?>

                <!-- code for the first item in slide -->
                <?PHP if ($cnt % 2): ?>
                <div class="item<?php if ($cnt == 1) { echo \' active\'; } ?>">
                <?PHP endif; ?>

                    <div class="col-md-6">
                        <?php  
                            $imagem_personalizada = get_field(\'capa_da_pagina_do_case\');
                            $thumb_capa = wp_get_attachment_image_src($imagem_personalizada, \'capaIdeia\');
                        ?>
                        <a href="<?php the_permalink();  ?>" style="text-decoration: none;">
                            <br>

                            <!-- code for the first item in slide -->
                            <?PHP if ($cnt % 2): ?>
                            <div id="secao-titulo-ideia-single" class="nopadding">
                            <!-- code for the second item in slide -->
                            <?PHP else: ?>
                            <div class="nopadding">
                            <?PHP endif; ?>

                                <img  class="img-responsive center-block" src="<?php echo $thumb_capa[0]; ?>" alt="Thumb Post" width="100%">

                                <!-- code for the first item in slide -->
                                <?PHP if ($cnt % 2): ?>
                                <h2 class="brandonregular titulo-ideia-single text-center"> <?php  the_field(\'titulo_do_case\'); ?> </h2>
                                <!-- code for the second item in slide -->
                                <?PHP else: ?>
                                <h2 class="brandonregular"> <?php  the_field(\'titulo_do_case\'); ?> </h2>
                                <?PHP endif; ?>
                            </div>
                        </a>
                </div>
                <!-- code for the second item in slide -->
                <?PHP if (!($cnt % 2)): ?>
                </div>
                <?PHP endif; ?>

            <?php $cnt++; ?>
            <?php endwhile; ?>

            <!-- code for closing the slide if only one item in the last slide -->
            <?PHP if (!($cnt % 2)): ?>
            </div>
            <?PHP endif; ?>
        </div>
    </div>
</article>

结束

相关推荐

Sidebar slideshow widget

有人知道可以放在边栏上的高质量图像幻灯片小部件吗?