douhu2890 2017-02-07 12:44
浏览 49

wordpress PHP每页显示3张幻灯片,带有bootstrap轮播

hello i tried to show 3 slide per page with bootstrap carousel but when I use wordpress php query it showed just 1 slide per page :( and for show another slide i should click on next... please see this http://bootsnipp.com/snippets/featured/responsive-moving-box-carousel I tried to code this by php query . my php code :

<div class="carousel slide" id="myCarousel">
    <div class="carousel-inner">
      <?php
$counter=0;
       ?>
        <div class="item <?php if($counter==0){echo 'active';} ?>">
                <ul class="thumbnails">
                  <?php
                  $my_query = new WP_Query('showposts=3&cat=1');
                  while ($my_query->have_posts()):
                  $my_query->the_post();
                  $do_not_duplicate = $post->ID;?>
                                  <li class="col-sm-4">
            <div class="shakhes">
              <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('shakhes') ?></a>

            <div class="caption"><a href="<?php the_permalink(); ?>">
              <h4><div class="livicon" data-name="chevron-left" data-size="30"  data-color="#555" data-hovercolor="#555" ></div><?php the_title(); ?></h4></a>
              <p><?php the_content_rss('', TRUE, '', 20); ?></p>
            <div class="moreshakhes">  <a href="<?php the_permalink(); ?>">مشاهده ادامه مطلب</a></div>
            </div>
                        </div>
                    </li>
<?php endwhile; ?>

                </ul>
          </div>
<?php $counter++; ?>


    </div>


 <nav>
  <ul class="control-box pager">
    <li><a data-slide="prev" href="#myCarousel" class=""><i class="glyphicon glyphicon-chevron-right"></i></a></li>
    <li><a data-slide="next" href="#myCarousel" class=""><i class="glyphicon glyphicon-chevron-left"></i></a></li>
  </ul>
</nav>
 <!-- /.control-box -->

</div><!-- /#myCarousel -->

</div>
  • 写回答

2条回答 默认 最新

  • douwu5009 2017-02-07 15:05
    关注

    You have written a wrong sctipt and used many depricated wordpress functions. the_content_rss function is deprecated and use the_content_feed and to show posts you have to use 'posts_per_page' instead showposts . I have rewritten your script with proper functions. Copy it from below and paste it to your template.I have checked the script and its working. Let me know if something wrong happen with you..

    <div class="carousel slide" id="myCarousel">
    <div class="carousel-inner">
        <?php
        $counter=0;
        ?>
        <div class="item <?php if($counter==0){echo 'active';} ?>">
            <ul class="thumbnails">
                <?php
                $my_query = new WP_Query(array(
                    'posts_per_page'   => 5,
                    'cat' => '1',
    
                    )
                );
    
                while ($my_query->have_posts()) : $my_query->the_post();
    
                $do_not_duplicate = $post->ID;?>
    
                <li class="col-sm-4">
                    <div class="shakhes">
                        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('shakhes') ?></a>
    
                        <div class="caption"><a href="<?php the_permalink(); ?>">
                            <h4><div class="livicon" data-name="chevron-left" data-size="30"  data-color="#555" data-hovercolor="#555" ></div><?php the_title(); ?></h4></a>
                            <p><?php the_content_feed('', TRUE, '', 20); ?></p>
                            <div class="moreshakhes">  <a href="<?php the_permalink(); ?>">مشاهده ادامه مطلب</a></div>
                        </div>
                    </div>
                </li>
            <?php endwhile; ?>
    
        </ul>
    </div>
    <?php $counter++; ?>
    </div>
    
    <nav>
        <ul class="control-box pager">
            <li><a data-slide="prev" href="#myCarousel" class=""><i class="glyphicon glyphicon-chevron-right"></i></a></li>
            <li><a data-slide="next" href="#myCarousel" class=""><i class="glyphicon glyphicon-chevron-left"></i></a></li>
        </ul>
    </nav>
    <!-- /.control-box -->
    
    </div><!-- /#myCarousel -->
    
    评论

报告相同问题?

悬赏问题

  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障