2014-09-04 152 views
0

我想讓我的循環重複打印6個圖像,然後結束ul和打印另外6個圖像並重復。引導Wordpress循環功能

但它一直在打印頁面,導致頁面中斷。

任何方式讓環路正常工作並正確地打印出來嗎?

頁面的鏈接是提前http://nerdclients.com/dev2/teena/all-pages/

謝謝!

<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 
     ?> 
+0

你有一個開口UL和2個UL元素 – Devin 2014-09-04 18:16:55

+0

最後UL是一個錯字我刪除它現在的感謝 – 2014-09-04 18:18:00

+0

你可以添加你想要生成的基本HTML結構? – 2014-09-04 18:23:40

回答

0

未經測試:

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

你需要修復第一件事是UL必須在循環中。 一旦進入你需要使用計數器來相應地顯示'ul'標籤。在我提供的未經測試的示例中,您會看到「ul」開始標記顯示在第一篇文章中,然後在第六篇文章的結尾處顯示。

此外,我做了一個計數器$ countposts來確定哪個帖子是最後一個,並顯示另一個關閉div與參數如果$ i等於$ countposts。我希望這能找到你。

  <?php 
      $i=0; 
$ireseti=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=''; 
       } 
     <?php if ($ireseti==1){ 
    echo '<ul class="col-lg-12 row">';} ?> 
      <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 ($ireseti == 6) {echo '</ul<!--end row-->' 
    <?php $ireseti=$ireseti+1; 

if ($ireseti==7){ 
$ireseti=1;} 
elseif ($countposts == $i) { echo '</div>';} ?> 
      <?php endwhile; ?> 

      <?php 
       $wp_query = null; 
       $wp_query = $temp; // Reset 
      ?>