获取基于特定类别的所有标签(包括来自子类别和帖子的所有标签) wordpress [英] Get all tags based on specific category (including all tags from child categories and posts) wordpress
本文介绍了获取基于特定类别的所有标签(包括来自子类别和帖子的所有标签) wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 single.php 上使用 wp_tag_cloud() 使用从特定类别获取所有标签的参数,包括来自其子类别和帖子的所有标签.
解决方案
我正在接近这个.
<h2>热门话题</h2><?php$category = get_the_category();$root_cat_of_curr = $category[0]->category_parent;函数 get_cat_slug($cat_id) {$cat_id = (int) $cat_id;$category = &get_category($cat_id);返回 $category->slug;}$my_cat = get_cat_slug($root_cat_of_curr);$custom_query = new WP_Query('posts_per_page=-1&category_name='.$my_cat.'');如果 ($custom_query->have_posts()) :而 ($custom_query->have_posts()) : $custom_query->the_post();$posttags = get_the_tags();如果($posttags){foreach($posttags 作为 $tag) {$all_tags[] = $tag->term_id;}}终了;万一;$tags_arr = array_unique($all_tags);$tags_str = implode(",", $tags_arr);$args = 数组('最小' =>12、'最大' =>24,'单位' =>'点','数字' =>0,'格式' =>'平坦的','分隔符' =>" ",'orderby' =>'姓名','订单' =>'兰德','排除' =>空值,'topic_count_text_callback' =>default_topic_count_text,'链接' =>'看法','回声' =>真的,'包括' =>$tags_str);wp_tag_cloud($args);?>
感谢大家的贡献.感谢您的帮助.
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.
解决方案
I am getting closer on this.
<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>
Thanks all for your contribution. Appreciate your help.
这篇关于获取基于特定类别的所有标签(包括来自子类别和帖子的所有标签) wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文