如果不使用插件,如何按名称排除多个类别?

时间:2012-08-15 01:46:10

标签: wordpress wordpress-theming

我有(2)我要从博客中排除的类别,如何在没有WP插件且名称不是ID的情况下执行此操作?

以下是代码:

<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('posts_per_page=5'.'&paged='.$paged); $exclude = get_cat_ID('feature');
$q = 'cat=-'.$exclude;
query_posts($q);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

试试这个:

$category_ids_to_ignore = array(3,4);  // replace 3 & 4 with the actual catgory ids you want to exclude
$posts = new WP_Query(array('category__not_in' => $category_to_ignore, 'posts_per_page' => 5, 'paged' => get_query_var('paged')));

while($posts->have_posts()) : $posts->the_post();
endwhile;