我想创建一个div,就像编辑器选择区一样,在每个类别页面的顶部显示标记为“editor-choice”的帖子。当然它只会显示当前类别页面的帖子。感谢
答案 0 :(得分:0)
如果有人感兴趣,请输入以下代码:
<?php
if (is_category( )) {
// this grabs the current category slug
$cat = get_query_var('cat');
$yourcat = get_category ($cat);
}
// this is the query to sort the tag only with the CURRENT CATEGORY by slug
$args = 'tag=editor-choice&category_name='.$yourcat->slug.'&category_title='.single_cat_title( '', false );
query_posts( $args );
// The Loop
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
wp_reset_query();
?>