How to make a given category listing as the home page in your Wordpress site?

| | 2 min read

In a Wordpress we can assign categories to each post and have listing of posts in each categories. Sometimes we need to list the contents of a particular category as the home page. In Wordpress we can make a static page as the home page under the settings tab, i.e. Settings » Reading settings. There you can make a static page as home page but not the contents in a category.

Quick Solution

So the solution should be something like this; We need to create a static page which lists the contents in a particular category and set this page as the home page.

How to create a static page with contents in a particular category

The first step to create a static page is to create a template file in the themes folder. For that your can make a copy of the page.php and name it something, say home.php. The contents of our template file should look like this.

<?php
/*
Template Name: Home page
*/
  get_header();
?>
<div class="content">
<?php
  query_posts('cat=4');
  while (have_posts()) : the_post();
    the_content();
  endwhile;
?>
</div>
<?php get_footer(); ?>

Code Explanation

The part of the code 'Template Name: Home page' names the template file for the Wordpress use. ie the name 'Home page' will appear as template suggestion when you create a page.'query_posts('cat=4');' will list the contents of of the category with id 4.

Next step is to create a static page in Wordpress. While creating a page you have to only enter a suitable title and a permalink. Don't forgot to select the template file we created under 'Page Attributes' section. Press the Publish button and now your static page with the contents in category id 4 is ready, you can also theme the contents of that page.

I think you already know how to set a static page as home page in Wordpress. So setting a category list as home page is as simple as you think. Simplicity is the main fact that makes Wordpress so popular.