2010-01-22 57 views
0

我有两类,可见光和hideMe ...WordPress的:找到1类职位,而不是在第2类

我想列出可见类别,这是很容易做到的所有帖子。但是,由于用户错误(或监督)可能有一些职位,在这两个类别。

我该如何拉动可见类别中的帖子,但不能在hideMe类别中?

这是我目前的解决方案。我只是不肯定get_posts方法是最便宜的选择,我可以用...

$cat=get_cat_ID('visible'); 
$cat2=get_cat_ID('hideMe'); 
$myposts = get_posts(array('cat' => "$cat,-$cat2",'showposts' => 5)); 
if($myposts) 
{//do something} 

回答

1

我不知道get_posts,但你签出query_posts?

Template Tags/query posts

它的工作方式是相同的get_posts,不知道这是否是不那么“贵”,但给它一个尝试

$catnow = 13; //replace with category id you want to pull 
$exception = ',-19,-18'; //replace with category ids you want to exclude 
$post_args = array('cat'=>$catnow.$exception); 
query_posts($post_args); 
if (have_posts()): while (have_posts()): the_post(); 
//do something to the posts 
endwhile; 
else: 
//no posts found 
endif; 
相关问题