How to Display Category Post on WordPress Blog Homepage

We do have a set of categories in which we classify the posts, and by default, all the new posts recently posted from all the categories appear on the home page of our WordPress blog. If you wish to show to your home page visitors only the new posts from some specified categories, that you specialize writing on, this is how you can do that.

In the wp-admin section of your WordPress blog, go to the Appearance=> Editor => home.php (if exists) or index.php (if home.php does not exist). You would get the Appearance tab on the left hand side of the admin panel and the template files on the right hand side.

You can also use FTP to open home.php or index.php inside the theme that you are selected. (Recommended for advance user or developer)

In the home.php or index.php code, search this line of code or wordpress loop.

Before the start of the WordPress loop, add the code below


where 1 is the category ID to be displayed or the category ID you want to show on blog homepage.

You can find the category IDs of the required categories by going to the Posts => Categories panel of the admin screen. Hover on any categoryname appearing on the right hand side of the panel, and you would see the Category ID in the link of the category in the browser status bar.

Below is the screenshot of the browser status bar showing the WordPress category ID.

You can tweak all categories to be displayed on the homepage by replacing the query_posts() code above in the code below.

Display posts that have these categories, using category id:

Display posts that have these categories, using category slug:

Display all posts except those from a category by prefixing its id with a ‘-‘ (minus) sign.

Display posts that are in multiple categories. This shows posts that are in both categories 2 and 6:

by Ryan Sutana

  • Harika

    Thanks a lot for the information provided.

    • page and post Ids and lot of my links went broken and I had to mlalnauy fix them. Also, there is bug for UTF-8 encoding in WordPress. I forgot to fix this before importing and all the Tamil text became ???? marks

  • This layout is so stellar. How did you manage to make a blog thats as smart as it can be sleek? I mean, its like an Aston Martin –smart and sexy at the identical time. Ive got to say, the layout alone made me come back to this weblog once again. But now that Ive read what youve got to say, Ive got to share it with the world!