2011-07-14 71 views
1

我試圖從側欄中列出的最近帖子中排除幾個類別。這是我得到的,但它不起作用($ ex部分是我想排除的地方)。任何建議表示讚賞:如何排除邊欄上的最近的帖子在WordPress的列表中的類別?

<?php 
     $latest = get_posts('numberposts=7'); 
     $i = 0; 
     $ex = "65,86"; 
     ?> 
     <?php foreach ($latest as $latest_post): $i++; ?> 
      <li <?php if ($i === 1) echo 'id="most_recent"' ?>><a href="<?php echo get_permalink($latest_post->ID) ?>"><?php echo $latest_post->post_title ?></a></li> 
     <?php endforeach ?> 
    </ul> 

</div> 

回答

0

我可能會使用自定義循環。如下面的代碼的東西應該工作:

<!--Set up your query here. In this example we're excluding cats 1, 2, 3 and displaying 5 posts--> 
<?php query_posts('cat=-1,-2,-3&posts_per_page=5'); ?>   

<!--Start the loop-->  
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 

<!--Your HTML and template tags here--> 
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> 

<?php endwhile; ?> 

<?php else: ?> 

<!-- Put something here in case there are not recent posts--> 

<?php endif; wp_reset_query();?> 
<!--Make sure you include the reset query function at the end here if you want other custom loops after this one--> 

使用查詢職位的好處是,你可以再使用在WordPress

http://codex.wordpress.org/Function_Reference/query_posts#Parameters

所有可用的其它參數
相關問題