Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过一次显示4个的帖子循环_Php_Wordpress_Slider_Cycle - Fatal编程技术网

Php 通过一次显示4个的帖子循环

Php 通过一次显示4个的帖子循环,php,wordpress,slider,cycle,Php,Wordpress,Slider,Cycle,我试图在Wordpress中的自定义帖子中创建一个滑块循环,每次显示4条。 我想让它在文章中循环,当它到达最后一篇文章时,再回到第一篇文章。 我的代码是: <div id="myCarousel" class="carousel slide"> <!-- Carousel items --> <div class="carousel-inner"> <div class="item active"> &

我试图在Wordpress中的自定义帖子中创建一个滑块循环,每次显示4条。 我想让它在文章中循环,当它到达最后一篇文章时,再回到第一篇文章。 我的代码是:

<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>





`


有人能帮忙吗?

到底什么不起作用?当循环结束时,比如说我有6个帖子,我希望它能重复到第一个帖子1-帖子2-帖子3-帖子4-帖子5-帖子6-帖子1-2-3-4-5等等。目前它没有这样做。如果我以后再添加更多的帖子,我只是希望它显示刚才重复的帖子。我明白,但是现在发生了什么?没有什么?没有显示任何内容?抱歉,当您循环浏览控件时,它会正确显示所有帖子,它将转到下一组帖子,但如果有6篇帖子,第一张幻灯片将显示4篇,然后下一张幻灯片将只显示2篇,在我希望循环的地方留下空白。问题是,只要有带有
的帖子,
,您就只能循环-您应该加载所有帖子,将其保存到数组中,对数组进行foreach,并始终在旋转木马中为每个视图创建4张幻灯片。