How to add category cloud in single post / page in WordPress

Category cloud can be added by using the taxonomy argument to cause a cloud of categories to display. You can either modify wp-content/yourtheme/single.php from ssh or using ftp OR you can login to wordpress dashboard, and go to “Appearance -> Editor -> ad click “single.php”

Post below line,

[php] <?php wp_tag_cloud( array( ‘taxonomy’ => ‘category’ ) ); ?> [/php]

After,

[php] <div class="thecontent"> <?php the_content(); ?> </div> [/php]

So, the final change could look like as below,

[php] <div class="thecontent"> <?php the_content(); ?> </div> <?php wp_tag_cloud( array( ‘taxonomy’ => ‘category’ ) ); ?> [/php]

To update into single page, modify the page.php as above.

If we want to customise the look of default Category cloud, we can modify the following code from wp-includes/category-template.php to add a border , and fill the color with boxed looks as below,

[php] // Generate the output links array. foreach ( $tags_data as $key => $tag_data ) { $class = $tag_data[‘class’] . ‘ tag-link-position-‘ . ( $key + 1 ); $a[] = sprintf( ‘<a href="%1$s"%2$s class="%3$s" style="font-size: %4$s; color: #fff; border: 1px solid; margin: 1px 1px; display: inline-block; padding: 5px 5px; background-color: #777;"%5$s>%6$s%7$s</a>’, ); } [/php]

Reference – https://codex.wordpress.org/Function_Reference/wp_tag_cloud#Display_a_Category_Cloud

Leave a Comment