我通过Likes(count)使用Custom Plugin(和meta_key)成功过滤了我的所有WordPress帖子(在自定义页面模板中),这也让我可以使用以下内容过滤特定类别中最喜欢的帖子
if (isset($_GET['category'])) {
$args = array(
'meta_key' => '_recoed',
'meta_compare' => '>',
'meta_value' => '0',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'category_name' => sanitize_text_field($_GET['category']),
'paged' => $paged
);
}
query_posts($args);
get_template_part('index');
The Category List to Filter the Posts for each Category (工作正常)
<?php $categories = get_categories('exclude=' . implode(',', my_blog_cats()) . ', 1'); ?>
<?php if ($categories) { ?>
<?php $categories = get_categories(); ?>
<?php foreach($categories as $category) { ?>
<li>
<a class="popular-categories" href="<?php echo get_permalink(); ?>?category=<?php echo $category->category_nicename; ?>"><?php echo $category->name; ?></a>
</li>
<?php endforeach; ?>
<?php } ?>
过滤帖子后的网址 - 例如 - 看起来像
.../hot-posts/?category=new-posts-category
Any idea how to echo only the current category name on the current page? 在示例的情况下,它将是"New Post Category"
1 回答
有3种可能性(WP类别的分类法是
category
):1) An ID - 如果
$_GET['category']
是WPcategory
term ID ,您将使用:2) A SLUG - 如果
$_GET['category']
是WPcategory
term SLUG ,您将使用:3) A NAME - 如果它已经是WP
category
terme NAME 只需使用: