【发布时间】:2021-06-03 11:41:11
【问题描述】:
我正在尝试在所有类别页面上,在显示帖子的循环上方建立一个“热门文章”区域。我在每个帖子上添加了一个“精选帖子”复选框,允许管理员将某些帖子标记为精选帖子,并且我已经能够在每个类别页面的顶部显示这些帖子。但它目前在所有类别页面上显示所有精选帖子,我需要系统过滤帖子以显示仅显示与它们显示的页面属于同一类别的帖子。
这是我在我的函数文件中使用的,它可以很好地显示特色帖子 - 感谢任何添加类别过滤的帮助!
$args = array(
'posts_per_page' => 5,
'meta_key' => 'meta-checkbox',
'meta_value' => 'yes'
);
$featured = new WP_Query($args);
if ($featured->have_posts()): while($featured->have_posts()): $featured->the_post(); ?>
<h3><a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a></h3>
<p class="details">By <a href="<?php the_author_posts() ?>"><?php the_author(); ?> </a> / On <?php echo get_the_date('F j, Y'); ?> / In <?php the_category(', '); ?></p>
<?php if (has_post_thumbnail()) : ?>
<figure> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> </figure>
<p ><?php the_excerpt();?></p>
<?php
endif;
endwhile; else:
endif;
?>```
【问题讨论】:
标签: wordpress categories posts