douhe6255 2014-09-04 18:14
浏览 28
已采纳

Bootstrap Wordpress循环功能

I am trying to get my loop to repeat print 6 images and then end the ul and print another 6 images and repeat.

But it keeps printing them all in the same ul which is causing the page to break.

Any way to get the loop to work properly and print it out correctly?

A link to the page is http://nerdclients.com/dev2/teena/all-pages/

Thanks in advance!

<ul class="col-lg-12">
        <?php
        $i=0;
        if ( get_query_var('paged') ) {
            $paged = get_query_var('paged');
        } else if ( get_query_var('page') ) {
            $paged = get_query_var('page');
        } else {
            $paged = 1;
        }

        $args = array('post_type' => 'array-portfolio', 'posts_per_page' => 1000, 'paged' => $paged );

        $temp = $wp_query;
        $wp_query = null;
        $wp_query = new WP_Query();
        $wp_query->query( $args );

        while ($wp_query->have_posts()) : $wp_query->the_post();
        $i++;
        if ($i%6==0){
           $class='last';
                                            }
        else {
           $class='';
             }
        ?>
        <li class="col-lg-2"<?php echo $class; ?>><a class="port-image" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail( 'port-image' ); ?></a></li>
        <?php endwhile; ?>
        </ul>
        <?php
           $wp_query = null;
           $wp_query = $temp;  // Reset
        ?>
  • 写回答

2条回答 默认 最新

  • duandaodao6951 2014-09-04 18:34
    关注

    untested:

    <ul class="col-lg-12">
      <?php
      $i=0;
      if ( get_query_var('paged') ) {
          $paged = get_query_var('paged');
      } else if ( get_query_var('page') ) {
          $paged = get_query_var('page');
      } else {
          $paged = 1;
      }
      $args = array('post_type' => 'array-portfolio', 'posts_per_page' => 1000, 'paged' => $paged );
      $temp = $wp_query;
      $wp_query = null;
      $wp_query = new WP_Query();
      $wp_query->query( $args );
      <?php
      while ($wp_query->have_posts()) : $wp_query->the_post();
        $i++;
        $class='';
        if ($i%6==0){
          $class='last';
        }
        ?>
        <li class="col-lg-2"<?php echo $class; ?>><a class="port-image" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail( 'port-image' ); ?></a></li>
        <?php
          if ($i%6==0){
          ?>
          </ul>
          <ul class="col-lg-12">
          <?php
        } 
      endwhile; ?>
    </ul>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#网络#的问题:网络是从楼上引一根网线下来,接了2台傻瓜交换机,也更换了ip还是不行
  • ¥15 资源泄露软件闪退怎么解决?
  • ¥15 CCF-CSP 2023 第三题 解压缩(50%)
  • ¥30 comfyui openpose报错
  • ¥20 Wpf Datarid单元格闪烁效果的实现
  • ¥15 图像分割、图像边缘提取
  • ¥15 sqlserver执行存储过程报错
  • ¥100 nuxt、uniapp、ruoyi-vue 相关发布问题
  • ¥15 浮窗和全屏应用同时存在,全屏应用输入法无法弹出
  • ¥100 matlab2009 32位一直初始化