2015-10-16 22 views
-1

嘿,我有這個WordPress的設置,我不是一個真正的PHP開發人員。我想要實現的是循環來排除最後創建的3個帖子。有沒有辦法去做到這一點?循環問題,我想去年3排除

  <div class="grid"> 

       <?php 
       // Start the loop. 
       while (have_posts()) : the_post(); ?> 
        <div class="col-sm-6 col-lg-4"> 
         <?php get_template_part('content', 'square'); ?> 
        </div> 
       <?php 
       // End the loop. 
       endwhile; ?> 

      </div><!-- .grid --> 

      <?php the_posts_pagination(array('mid_size' => 2, 'prev_text' => '<span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span>', 'next_text' => '<span class="glyphicon glyphicon-menu-right" aria-hidden="true"></span>')); 

      // If no content, include the "No posts found" template. 
     else : 
      get_template_part('content', 'none'); 
     endif; 
     ?> 
+0

它可能更適合這樣做,因爲自定義查詢... – rnevius

回答

0

定義計數總員額變量($數= [總帖]),然後通過該帖子使用for循環設置你的最大迭代$重複計數3:

for($i=0; $i<($count-3); $i++){ 
    do something; 
} 
0

的員額數爲這樣的「標準」循環存儲在全球$wp_query。要訪問它,你可以使用$GLOBALS['wp_query']->post_count

<?php 
// Get the post count and set a counter variable 
$count = $GLOBALS['wp_query']->post_count; $i = 0; 
while (have_posts() && $i < $count - 3) : the_post(); ?> 

    <!-- Post content loop --> 

<?php $i++; endwhile; ?> 

請記住,如果你有3級以上的職位,這隻會工作...