Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 如果不使用插件,如何按名称排除多个类别?_Wordpress_Wordpress Theming - Fatal编程技术网

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

Wordpress 如果不使用插件,如何按名称排除多个类别?,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我有(2)个类别,我想从博客中排除,我如何做到这一点,没有可湿性粉剂插件和名称,而不是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_

我有(2)个类别,我想从博客中排除,我如何做到这一点,没有可湿性粉剂插件和名称,而不是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();
?>

谢谢你的帮助

试试这个:

$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; 

您在代码中使用了两种不同的方法(WP\u Query和Query\u posts)来检索帖子。这是有意的吗?若您不确定使用哪一个,请查看图表。这是我最喜欢的Wordpress图表之一。您可以使用WP_Query()或Query_posts()实现您想要实现的目标。一旦你选择了使用哪种方法,如果你需要进一步的帮助,请告诉我。谢谢,我会保存它。我把它清理干净,允许分页。我怎么能只用一个?我不是PHP专家。虽然分页在这里有效,但我仍然只能从博客中排除1个类别。