Displaying one category on your Wordpress main page

If you would like to only display a single category on your WordPress main page, here’s how you do it. You will need to start out by getting ID of the category you wish to display.   In WordPress 2.7+,  start out by going to your categories tab under posts(1), then hover over the category you would like to display in your post(2), don’t click on it, just hover over it.  On the bottom of your screen, you will be shown then URL of the category your hover over(3), remember the ID number that being displayed.   In the below example the number we need to remember is “23″.

Getting Category id

After you have gotten your categories ID number, you will next need to change your index.php file.  In your index.php file look for the line with “have_post” and add the below code after.

<?php if (have_posts()) : ?>; \\Look for this line and add below
<?php query_posts('showposts=10&amp;;cat=23'); ?>;
<?php while (have_posts()) : the_post(); ?>;

Last, change “cat” to the category id from above. “showposts” is the number of posts to display on the page.

4 Comments

  1. Bryan says:

    Could’nt this be done on the page.php file instead?
    Does modifing inddex.php effect other pages created?

  2. Matt Rude says:

    Not really, since pages don’t have categories.

    Depending on your theme, some only use the index.php file for the main page. It all depends if you have other files in your theme like archive.php, category.php, tag.php and so on.

  3. Rik says:

    It should be:

    I think something went wrong in your copy-paste to your page. Showposts isn’t really neccesary. Anyway, strange bug: If I click “older entries”, it does go back, but again with the latest posts. It did it before, but since this mod it’s over.

    Any thoughts?

    1. Matt Rude says:

      Yeah, it looks like your right, something went wrong. I know that showed correctly at one point.

Leave a Comment