douyao1994 2015-03-25 09:53 采纳率: 100%
浏览 43

循环显示一次显示4个帖子

I am trying to make a slider cycle through the custom posts in Wordpress, displaying 4 at a time. I would like it to cycle through the posts and just loop back to the first one when it has reached the last post. My code is:

<div id="myCarousel" class="carousel slide">

  <!-- Carousel items -->
  <div class="carousel-inner">
     <div class="item active">
             <div class="row">
               <?php 
      $args = array(
     'posts_per_page' => '4',
     'post_type' => 'dogs',
      );

      $myDogs = new WP_Query( $args ); ?>
       <?php while ( $myDogs->have_posts() ) : $myDogs->the_post();?>
                 <div id="sl-cont" class="col-sm-12 col-md-3 col-lg-3">
                       <div class="well">
                              <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('slider-size'); ?></a>
                             <div class="dog-caption">
                               <p><span class="title"><?php the_title(); ?></span><br/>
                               <?php the_excerpt(); ?><br/>
                               <a href="<?php the_permalink() ?>">Read more >> </a></p>
                             </div>
                       </div><!--end of well-->

                 </div><!--end of container-->
                  <?php endwhile;
                  wp_reset_postdata();?>

             </div>
         <!--/row-->
     </div>
     <!--/item-->

     <div class="item">
             <div class="row">
               <?php 
      $args = array(
     'posts_per_page' => '4',
     'post_type' => 'dogs',
     'offset' => 1
      );

      $myDogs = new WP_Query( $args ); ?>
       <?php while ( $myDogs->have_posts() ) : $myDogs->the_post();?>
                 <div id="sl-cont" class="col-sm-12 col-md-3 col-lg-3">
                       <div class="well">
                              <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('slider-size'); ?></a>
                             <div class="dog-caption">
                               <p><span class="title"><?php the_title(); ?></span><br/>
                               <?php the_excerpt(); ?><br/>
                               <a href="<?php the_permalink() ?>">Read more >> </a></p>
                             </div>
                       </div><!--end of well-->

                 </div><!--end of container-->
                  <?php endwhile;
                  wp_reset_postdata();?>

             </div>
         <!--/row-->
     </div>
     <!--/item-->

  </div>  <!--/carousel-inner-->
<a class="left carousel-control" href="#myCarousel" data-slide="prev"><img src="<?php bloginfo('template_directory'); ?>/img/left-paw.png"> </a>
<a class="right carousel-control" href="#myCarousel" data-slide="next"><img src="<?php bloginfo('template_directory'); ?>/img/right-paw.png"></a>

`

Can anyone help?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 路易威登官网 里边的参数逆向
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决
    • ¥15 processing提取音乐节奏
    • ¥15 gg加速器加速游戏时,提示不是x86架构
    • ¥15 python按要求编写程序
    • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入