If we have a website which is largely text based, something like this website which shows mostly text posts then its always better to have a home page which lists all the categories so user can choose the category they want and we display the posts under that category on next category pages. For getting the list of categories, wordpress provides an API “ wp_list_categories ” using which we can get the list of all categories. This API also accepts an arguments which can be used to customise look and features of category listing.

Command line execution

Terminalbash
sed to customise look and features of category listing. To add categories on home page modify your wordpress based websites source code as below, <?php if ( is_home() || is_front_page() ) : ?>     <?php wp_list_categories(array(         'hierarchical'        => false,         'style'               => 'list',         'separator'           => '<hr>',         'depth'               => '2',         'order'               => 'ASC',         'orderby'             => 'name',         'show_count' => true     ) ); ?> <?php endif; ?> details of more supported arguments for “wp_list_categories” can be found at wordpress website (  Link  ). As an example, we will show here how we added this to our wordpress based website’s home page, $ vim wp-content/themes/mywebsite_theme/page.php opened page.php from our website’s theme and pasted below code, <div class="single_page">     <header>         <h1 class="title entry-title"><?php the_title(); ?></h1>     </header>    <?php if ((is_home() || is_front_page()) && !is_tag()) : ?> <?php wp_list_categories(array(         'hierarchical'        => false,         'style'               => 'list',         'separator'           => '<hr>',         'depth'               => '2',         'order'               => 'ASC',         'orderby'             => 'name'     ) ); ?>     <?php endif; ?> </div> If you want to display subcategories on navigation pages, you can visit our post  “Display all subcategories from a specific category on selected Category Archive page ?”

Risk level: destructive. Review the command before running it.

Implementation details

To add categories on home page modify your wordpress based websites source code as below, <?php if ( is_home() || is_front_page() ) : ?> <?php wp_list_categories(array( 'hierarchical' => false, 'style' => 'list', 'separator' => '<hr>', 'depth' => '2', 'order' => 'ASC', 'orderby' => 'name', 'show_count' => true ) ); ?> <?php endif; ?> details of more supported arguments for “wp_list_categories” can be found at wordpress website ( Link ). As an example, we will show here how we added this to our wordpress based website’s home page, $ vim wp-content/themes/mywebsite_theme/page.php opened page.php from our website’s theme and pasted below code, <div class="single_page"> <header> <h1 class="title entry-title"><?php the_title(); ?></h1> </header> <?php if ((is_home() || is_front_page()) && !is_tag()) : ?> <?php wp_list_categories(array( 'hierarchical' => false, 'style' => 'list', 'separator' => '<hr>', 'depth' => '2', 'order' => 'ASC', 'orderby' => 'name' ) ); ?> <?php endif; ?> </div> If you want to display subcategories on navigation pages, you can visit our post “Display all subcategories from a specific category on selected Category Archive page ?”

Gotchas and common issues

  • Permission checks - verify user access rights and sudo privileges before executing system-level operations.

  • Environment configuration - double-check path variables and dependency versions to prevent runtime failures.

  • Backup safeguards - maintain configuration backups before applying system or database modifications.

Following these steps ensures clean configuration and reliable execution for display wordpress categories on home page of website.