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 wp_tag_cloud( array( 'taxonomy' => 'category' ) ); ?>

After,

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

So, the final change could look like as below,

<div class="thecontent">
    <?php the_content(); ?>
</div>
<?php wp_tag_cloud( array( 'taxonomy' => 'category' ) ); ?>

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,

        // 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>',
                );
        }

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

Android Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Commands and Packages Compilation Content Management System - CMS Core Kernel C Programs Development & Build Development Environment Setup Errors & Failures Flutter git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense Multimedia - Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized User Interface Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply / Ask Question