如何解决使用不同的偏移量查询不同循环中的不同类别
我有四个循环。在第一个循环中,我想显示所有类别的所有当前文章(突发新闻)。在第二个循环中,只应显示类别为 4、5、6、7 的文章。但是,如果在第 1 次循环中发表了这些类别的文章,则这篇最新文章不应出现在第 2 次循环中。到目前为止,我只阅读了文章的一般排除,而没有阅读条件。
解决方法
您必须使用 category__not_in
:
$include_cats = array( 4,5,6,7 );
$exclude_cats = array( 3 ); // 'breaking news' TERM ID
$posts_args = array(
'post_type' => 'post','post_status' => 'publish','posts_per_page' => 4,'ignore_sticky_posts' => true,'category__in' => $include_cats,'category__not_in' => $exclude_cats,'orderby' => 'date',);
$posts = new WP_Query( $posts_args );
if ( $posts->have_posts() ) {
while ( $posts->have_posts() ) {
$posts->the_post();
?>
<a href="<?php echo get_the_permalink( $posts->post->ID ); ?>" title="<?php echo get_the_title( $posts->post->ID ); ?>">
<?php
if ( has_post_thumbnail( $posts->post->ID ) ) {
echo get_the_post_thumbnail( $posts->post->ID,$img,array( 'class' => 'post-thumb' ) ); // YOUR IMAGE SIZE
} else {
echo '<img class="' . $img . '" src="placeholder.png" width="150" height="150" alt="' . get_the_title( $posts->post->ID ) . '">'; //ADD PLACEHOLDER IMAGE HERE
}
?>
<h3 class="post-title"><?php echo get_the_title( $posts->post->ID ); ?></h3>
<span class="author"><?php echo get_the_author( $posts->post->ID ); ?></span>
</a>
<?php
}
}
wp_reset_postdata();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。