【发布时间】:2015-03-16 00:18:28
【问题描述】:
谁能解释为什么这个查询不起作用? 我想排除带有主页标记的帖子。 它仍然显示类别名称为“主页”的帖子...
<?php
$query = new WP_Query( 'category_name=-homepage');
?>
<?php if ( $query->have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
get_template_part( 'content', 'news' );
?>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
【问题讨论】:
-
也试过 $query = new WP_Query( 'cat=-11' );但它也不起作用。
-
不相关...但是伙计,摆脱所有那些
<?php ?>标签... -
你还需要把
while ( have_posts() ) : the_post();改成while ( $query->have_posts() ) : $query->the_post();。 -
谢谢内森!好像是这个问题!我忽略了它!
-
@rnevius 我该怎么做? (还在学习中……)