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 に答える