如何在wordpress上排除带有标记的帖子?
我想在侧边栏中显示5篇文章,不包括我标记为“hp”(ID=11)的所有文章。显然,有很多方法可以使用类别来实现这一点,但是使用标签确实很难找到 这是我的密码如何在wordpress上排除带有标记的帖子?,wordpress,tags,content-management-system,Wordpress,Tags,Content Management System,我想在侧边栏中显示5篇文章,不包括我标记为“hp”(ID=11)的所有文章。显然,有很多方法可以使用类别来实现这一点,但是使用标签确实很难找到 这是我的密码 <?php query_posts( array( 'tag' => -11, 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC' ) ); ?> <?php while (have_posts()) : the_post();
<?php query_posts( array( 'tag' => -11, 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC' ) ); ?>
<?php while (have_posts()) : the_post(); ?>
<?php if (class_exists('MultiPostThumbnails')
&& MultiPostThumbnails::has_post_thumbnail('post', '3-image')) :
MultiPostThumbnails::the_post_thumbnail('post', '3-image'); endif; ?>
<div>in <?php the_category(', '); ?></div>
<?php the_title(); ?>
<?php
$count = 0;
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$count++;
if ($count <= 1 ) {
echo '<a href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a> ';
}
}
}
?>
<?php endwhile;?>
在里面
它只显示了5篇文章,只显示了第一个标记,但它保留了我试图排除的标记的文章 您需要使用
WP\u Query
类以及tag\uu not\u in
<?php
$the_query = new WP_Query( array( 'tag__not_in' => array( 11 ) ) );
while ( $the_query->have_posts() ) : $the_query->the_post();
// Whatever you want to do goes here
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
您可以在这里获得有关
WP\u Query
类的更多信息-它工作得非常好,非常感谢!但是,我如何告诉他只显示5篇文章呢?你可以提供与之前相同的论点。