2014-03-01 66 views
0

我有一个正常的wordpress循环的第一篇文章,但我想永远隐藏从这个循环特定类别的最新讯息。有任何想法吗?隐藏特定类别中环

回答

0

使用一个布尔变量来检查您是否已经跳过了一个职位在该类别中,像这样:

<?php 
$post_has_been_skipped = FALSE; 
if (have_posts()) { 
    while (have_posts()) { 
     the_post(); 
     if (!$post_has_been_skipped AND in_category("your-category-slug")) { 
      $post_has_been_skipped = TRUE; 
      continue; 
     } 
     // 
     // Post Content here 
     // 
    } // end while 
} // end if 
?> 
0
<?php 
$categories = array(); 
if (have_posts()) { 
    while (have_posts()) { 
        $category = the_category(); 
        if (in_array($category)) { 
          the_post(); // code after the 1st one is skipped. 
        } else { 
          $categories[] = $category; // when it's the first post, add the category so the next posts will display. 
        } 
    } // end while 
} // end if 
?> 

这应该是你的循环的基本结构。

逻辑:如果类别是第一,它不会在$类别存在,所以它增加了它和移动对下一个柱,如果类别是已经它显示的代码在数组中。