0

我有 (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();
?>

谢谢你的帮助!

4

1 回答 1

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; 
于 2012-08-16T02:31:05.230 回答