Wordpress . , , . - .
, .
functions.php.
function get_tags_in_use($category_ID, $type = 'name'){
$my_posts = new WP_Query(array(
'cat' => $category_ID,
'posts_per_page' => -1
));
$tags_by_id = array();
$tags_by_name = array();
$tags_by_slug = array();
if ($my_posts->have_posts()): while ($my_posts->have_posts()): $my_posts->the_post();
$post_tags = wp_get_post_tags($my_posts->post->ID);
foreach ($post_tags as $tag):
$tag_id = $tag->term_id;
$tag_name = $tag->name;
$tag_slug = $tag->slug;
if (!in_array($tag_id, $tags_by_id))
array_push($tags_by_id, $tag_id);
if (!in_array($tag_name, $tags_by_name))
array_push($tags_by_name, $tag_name);
if (!in_array($tag_slug, $tags_by_slug))
array_push($tags_by_slug, $tag_slug);
endforeach;
endwhile; endif;
if ($type == 'id')
return $tags_by_id;
if ($type == 'name')
return $tags_by_name;
if ($type == 'slug')
return $tags_by_slug;
}
, , :
// First paramater is the category and the second paramater is how to return the tag (by name, by id, or by slug)
// Leave second paramater blank to default to name
$tags = get_tags_in_use(59, 'name');
, .
EDIT:
, :
function tag_cloud_by_category($category_ID){
$tags = get_tags_in_use($category_ID, 'id');
echo '<div class="tag-cloud">';
foreach ($tags as $tag):
$term = get_term_by('id', $tag, 'post_tag');
$count = $term->count;
$tag_info = get_tag($tag);
$tag_name = $tag_info->name;
$tag_link = get_tag_link($tag);
$size = 8 + $count;
echo '<span style="font-size:'.$size.'px;">';
echo '<a href="'.$tag_link.'">'.$tag_name.'</a>';
echo ' </span>';
endforeach;
echo '</div>';
}
, :
tag_cloud_by_category($cat_id);