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

报告相同问题?