获取基于特定类别的所有标签(包括来自子类别和帖子的所有标签)wordpress [英] Get all tags based on specific category (including all tags from child categories and posts) wordpress
本文介绍了获取基于特定类别的所有标签(包括来自子类别和帖子的所有标签)wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 single.php 上使用 wp_tag_cloud() 使用参数,该参数从特定类别中获取所有标签,包括来自其子类别和帖子的所有标签.
I wanted to use wp_tag_cloud() on single.php using the argument that gets all tags from specific category including all tags from its child categories and posts.
推荐答案
我越来越接近这个了.
<div class="tag_cloud_on_single">
<h2>Popular Topics</h2>
<?php
$category = get_the_category();
$root_cat_of_curr = $category[0]->category_parent;
function get_cat_slug($cat_id) {
$cat_id = (int) $cat_id;
$category = &get_category($cat_id);
return $category->slug;
}
$my_cat = get_cat_slug($root_cat_of_curr);
$custom_query = new WP_Query('posts_per_page=-1&category_name='.$my_cat.'');
if ($custom_query->have_posts()) :
while ($custom_query->have_posts()) : $custom_query->the_post();
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$all_tags[] = $tag->term_id;
}
}
endwhile;
endif;
$tags_arr = array_unique($all_tags);
$tags_str = implode(",", $tags_arr);
$args = array(
'smallest' => 12,
'largest' => 24,
'unit' => 'pt',
'number' => 0,
'format' => 'flat',
'separator' => " ",
'orderby' => 'name',
'order' => 'RAND',
'exclude' => null,
'topic_count_text_callback' => default_topic_count_text,
'link' => 'view',
'echo' => true,
'include' => $tags_str
);
wp_tag_cloud($args);
?>
</div>
感谢大家的贡献.感谢您的帮助.
这篇关于获取基于特定类别的所有标签(包括来自子类别和帖子的所有标签)wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文