For those that need the Category Tag Cloud display (like the category cloud) – Template 2
<?php
$category = get_query_var('cat');
$current_cat = get_category($cat);
$custom_query = new WP_Query( 'posts_per_page=-1&category_name='.$current_cat->slug.'' );
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' => 12,
'unit' => 'px',
'number' => 0,
'format' => 'flat',
'include' => $tags_str
);
wp_tag_cloud( $args );
?>
Styling with .td-post-small-box a, just add .tag-cloud-link
.td-post-small-box a, .tag-cloud-link{
display: block;
float: left;
border: 1px solid #1b5b5b;
margin-left: 4px;
line-height: 8px;
color: #ffffff;
padding: 5px 8px;
height: 20px;
background-color: #1b5b5b;
}
Correction:
<?php
$category = get_query_var('cat');
$current_cat = get_category($cat);
$custom_query = new WP_Query( 'posts_per_page=-1&category_name='.$current_cat->slug.'' );
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;
if(is_array($all_tags)){
$tags_arr = array_unique( $all_tags );
$tags_str = implode( ",", $tags_arr );
$args = array(
'smallest' => 12,
'largest' => 12,
'unit' => 'px',
'number' => 5,
'format' => 'flat',
'include' => $tags_str
);
echo '<div id="tagcloud"><h3>Popular Tags</h3>';
wp_tag_cloud( $args );
echo '</div>';
}
?>
Final Correction sorry, working outside the loop:
<?php
global $post;
get_the_category( $id );
if ( is_category($id) ) {
$current_category = single_cat_title("", false);
query_posts('category_name='.$current_category.'');
if (have_posts()) : while (have_posts()) : the_post();
if( get_the_tag_list() ){
echo '<div id="tagcloud"><h3>Popular Tags for '.$current_category.'</h3>';
echo $posttags = get_the_tag_list('
');
echo '</div>';
}
endwhile; endif;
wp_reset_query();
}
?>
-
This reply was modified 8 years by
acdmin.