Given are 5 categories & their sub-categories in my WordPress Website. Sub-categories contains posts. I want to display categories (Only categories) on my front page. When a user click on any category, I want to show it’s all sub-categories on another page and when user click on any sub-category, I want to display all the posts that category contains.
Please tell me how to do it? I have studied WordPress category guides but did not get any clue.
Add the following code to your front page template:
wp_list_categories();
That will print out a list of all your categories. You can then hide the subcategories if you wish using CSS.
By default, clicking a category link will then open the category page, which uses the category.php template, and this will show all the posts in that category.
More information here: https://codex.wordpress.org/Template_Tags/wp_list_categories
To list the subcategories of a particular category: