\u8be6\u60c5<\/a><\/li><\/ul>\n\n\n\n\u6211\u5df2\u7ecf\u7f16\u5199\u4e86\u4e00\u4e2a\u5feb\u901f\u529f\u80fd\u6765\u505a\u5230\u8fd9\u4e00\u70b9\u3002<\/p>\n\n\n\n
\uff08\u5305\u62ec\u5b50\u7c7b\u522b\u548c\u5e16\u5b50\u4e2d\u7684\u6240\u6709\u6807\u7b7e\uff09<\/p>\n\n\n\n
\u5c06\u6b64\u51fd\u6570\u653e\u5165\u60a8\u7684functions.php\u6587\u4ef6\u4e2d\u3002<\/p>\n\n\n\n
function get_tags_in_use($category_ID, $type = 'name'){\r\n \/\/ Set up the query for our posts\r\n $my_posts = new WP_Query(array(\r\n 'cat' => $category_ID, \/\/ Your category id\r\n 'posts_per_page' => -1 \/\/ All posts from that category\r\n ));\r\n\r\n \/\/ Initialize our tag arrays\r\n $tags_by_id = array();\r\n $tags_by_name = array();\r\n $tags_by_slug = array();\r\n\r\n \/\/ If there are posts in this category, loop through them\r\n if ($my_posts->have_posts()): while ($my_posts->have_posts()): $my_posts->the_post();\r\n\r\n \/\/ Get all tags of current post\r\n $post_tags = wp_get_post_tags($my_posts->post->ID);\r\n\r\n \/\/ Loop through each tag\r\n foreach ($post_tags as $tag):\r\n\r\n \/\/ Set up our tags by id, name, and\/or slug\r\n $tag_id = $tag->term_id;\r\n $tag_name = $tag->name;\r\n $tag_slug = $tag->slug;\r\n\r\n \/\/ Push each tag into our main array if not already in it\r\n if (!in_array($tag_id, $tags_by_id))\r\n array_push($tags_by_id, $tag_id);\r\n\r\n if (!in_array($tag_name, $tags_by_name))\r\n array_push($tags_by_name, $tag_name);\r\n\r\n if (!in_array($tag_slug, $tags_by_slug))\r\n array_push($tags_by_slug, $tag_slug);\r\n\r\n endforeach;\r\n endwhile; endif;\r\n\r\n \/\/ Return value specified\r\n if ($type == 'id')\r\n return $tags_by_id;\r\n\r\n if ($type == 'name')\r\n return $tags_by_name;\r\n\r\n if ($type == 'slug')\r\n return $tags_by_slug;\r\n}<\/code><\/pre>\n\n\n\n\u7136\u540e\uff0c\u5f53\u60a8\u8981\u83b7\u53d6\u7279\u5b9a\u7c7b\u522b\u7684\u6807\u7b7e\u65f6\uff0c\u8bf7\u50cf\u4e0b\u9762\u8fd9\u6837\u8c03\u7528\u6b64\u51fd\u6570\uff1a<\/p>\n\n\n\n
\/\/ First paramater is the category and the second paramater is how to return the tag (by name, by id, or by slug)\r\n\/\/ Leave second paramater blank to default to name\r\n\r\n$tags = get_tags_in_use(59, 'name');<\/code><\/pre>\n\n\n\n\u5e0c\u671b\u8fd9\u53ef\u4ee5\u5e2e\u52a9\u3002<\/p>\n\n\n\n
\u7f16\u8f91\uff1a<\/p>\n\n\n\n
\u8fd9\u662f\u60a8\u9700\u8981\u4e0e\u5176\u4ed6\u529f\u80fd\u7ed3\u5408\u4f7f\u7528\u7684\u529f\u80fd\uff1a<\/p>\n\n\n\n
function tag_cloud_by_category($category_ID){\r\n \/\/ Get our tag array\r\n $tags = get_tags_in_use($category_ID, 'id');\r\n\r\n \/\/ Start our output variable\r\n echo '<div class=\"tag-cloud\">';\r\n\r\n \/\/ Cycle through each tag and set it up\r\n foreach ($tags as $tag):\r\n \/\/ Get our count\r\n $term = get_term_by('id', $tag, 'post_tag');\r\n $count = $term->count;\r\n\r\n \/\/ Get tag name\r\n $tag_info = get_tag($tag);\r\n $tag_name = $tag_info->name;\r\n\r\n \/\/ Get tag link\r\n $tag_link = get_tag_link($tag);\r\n\r\n \/\/ Set up our font size based on count\r\n $size = 8 + $count;\r\n\r\n echo '<span style=\"font-size:'.$size.'px;\">';\r\n echo '<a href=\"'.$tag_link.'\">'.$tag_name.'<\/a>';\r\n echo ' <\/span>';\r\n\r\n endforeach;\r\n\r\n echo '<\/div>';\r\n}<\/code><\/pre>\n\n\n\n\u56e0\u6b64\uff0c\u60a8\u53ef\u4ee5\u50cf\u4e0b\u9762\u8fd9\u6837\u7b80\u5355\u5730\u4f7f\u7528\u6b64\u529f\u80fd\uff1a<\/p>\n\n\n\n
tag_cloud_by_category($cat_id);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u6807\u7b7e\u4e0d\u4f9d\u8d56\u4e8e\u7c7b\u522b\uff0c\u5b83\u4eec\u662f\u5206\u5f00\u7684\u3002\u8bdd\u867d\u8fd9\u4e48\u8bf4\uff0c\u8981\u4f7f\u67d0\u4e2a\u7279\u5b9a\u7c7b\u522b\u7684\u6240\u6709\u6807\u7b7e\u90fd\u5728\u4f7f\u7528\u4e2d\uff0c\u552f\u4e00\u7684\u65b9\u6cd5\u662f\u5faa\u73af\u6d4f\u89c8\u8be5\u7c7b\u522b\u7684\u6bcf\u4e2a\u5e16\u5b50\u5e76\u83b7\u53d6\u6bcf\u4e2a\u5e16\u5b50\u7684\u6807\u7b7e<\/p>\n","protected":false},"author":1,"featured_media":15298,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[579],"collection":[],"class_list":["post-19997","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-course","tag-wp-course"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/posts\/19997"}],"collection":[{"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/comments?post=19997"}],"version-history":[{"count":0,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/posts\/19997\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/media\/15298"}],"wp:attachment":[{"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/media?parent=19997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/categories?post=19997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/tags?post=19997"},{"taxonomy":"collection","embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/collection?post=19997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}