【发布时间】:2016-01-26 17:23:01
【问题描述】:
我需要制作一个“公告”横幅,显示 5 个最新帖子,其中一个 MUST 是最新的时事通讯。
我想做的是:最新的 4 篇不包括时事通讯类别的帖子 + 最新的时事通讯帖子作为第 5 个帖子。
这怎么可能?
我尝试过tax_query,但它只显示newsletter类别,并且不限制该特定类别。
我尝试从 newsletter 类别中排除所有帖子 ID,但如果最近 5 个帖子中没有新闻通讯,则根本不会显示最新的新闻通讯。
代码:
$category_id = get_cat_ID('Newsletter');
$latest_newsletter = query_posts("cat=$category_id&order_by=date");
$exclude_ids = [];
$count = 0;
while (have_posts()) : the_post();
$post = get_post();
if($count > 0) {
$exclude_ids[] = $post->ID;
}
$count++;
endwhile;
wp_reset_query();
query_posts(['posts_per_page' => '4', 'order_by' => 'date', 'post__not_in' => $exclude_ids]); if (have_posts()) : ?>
<div class="news-announcement">
<h3>ANNOUNCEMENT</h3>
<div id="ticker" class="ticker">
<ul>
<?php while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="Continue reading"> continue reading...</a>
<?php the_title( ); ?></li>
<?php endwhile; ?>
</ul>
</div>
</div>
有什么想法吗?
【问题讨论】: