WordPress Themes Blog Oh! Blog

Hacking WordPress

Many people have asked me how to show posts on their homepage only from a particular category or categories. So here is a simple and quick solution for doing this.

Getting Posts from a Single Category

Go and open your index.php file from your theme folder. Now search for this string :-

Now just below this line, add the following piece of code:-

The above code will display posts only from the category called “General” on your home page. You can change this to any of your category names.

Getting Posts from more than one Category

In another case, if you want to show posts from more than one category (for example “General” and “Graphics”), you will have to use the category IDs and the code will be written like this:-

In the above example, I have assumed that the category ID for “General” is 1 and for “Graphics” its 2. You can get the ID for your categories by going to Manage->Categories in your wp-admin.

Excluding Posts from certain Categories

And if you want WordPress the exclude posts from some category, just put the “-” (minus) sign in front of the category ID like this:-

The above code will show all the posts on your home page except from the categories with ID 1 and 2.

I hope this is helpful for everyone.

  1. Elon Clark left a comment on March 13, 2021 at 5:31 am |

    The tutorial was really impressive and informative. Thanks for sharing that blog!

  2. parsa left a comment on November 10, 2020 at 12:46 am |

    your article is usefull and help me and h will use this in my new website https://www.parsajetprinter.com/

  3. FXGM left a comment on October 22, 2020 at 9:35 am |

    It’s near impossible to find well-updated women and men on this subject, and yet you come across as like you comprehend whatever you’re writing about! Thanks A Lot.. FXGM

  4. Tina left a comment on March 30, 2016 at 9:00 pm |

    HGIT is the professional manufacturer for Filter gasket sealing machine, this machine can be used in Filter, cabinet, lighting, battery, etc.
    The Company specially develops a German Beckhoff dispensing operation system with independent intellectual property rights which makes graphic processing more user-friendly and hardware failure rate lower.
    The unique remote service performance makes on-line synchronous dialog, diagnosis with camera shooting and timely zero-distance after-sales service achievable.
    Operation interface is indicated in both Chinese and English; if there is any need, other languages can be added. The system boasts functions such as false operation reminding, idiot-proof protection, overpressure alarming, temperature alarming and low material level reminding.

  5. Telecharger left a comment on October 19, 2012 at 10:14 am |

    Thanks, great timing as I need this one now.

  6. http://www.theuscoachoutlet.com left a comment on October 9, 2012 at 3:14 am |

    Many people have asked me how to show posts on their homepage only from a particular

  7. Zina Crincoli left a comment on September 2, 2012 at 1:30 pm |

    Not there either. I found what I was looking for at http://DoWeSync.com . They sync People not Data..

  8. Anne Armel left a comment on June 22, 2012 at 2:54 pm |

    I have learn some excellent stuff here. Definitely worth bookmarking for revisiting. I wonder how a lot attempt you put to create this type of wonderful informative web site.

  9. my blog left a comment on April 17, 2012 at 1:45 pm |

    Not long ago i found your blog and have been looking at together. I have seen several unusual feedback, nevertheless generally I’ve got to agree with what are the additional commenters are generally writing. With the amount of greatgreat testimonials of this weblog, I figured that i also need to start along with advise you that I enjoyed scanning this your articles. Therefore i think this would help to make my 1st opinion: “I consider you have produced a few truly intriguing items. Very few men and women would actually think about it the way you only did. Now i’m actually impressed that there are a great deal about this topic that have been discovered and also you made it happen consequently well, with a great deal class!inch

  10. movovi left a comment on October 3, 2011 at 12:20 am |

    Very helpful. Thanks !

  11. Boloindia left a comment on December 8, 2010 at 8:01 am |

    I am not a coder but it sure helped me in a way. Now i excluded some category posts on my website and it looks stunning. πŸ™‚ Thanks by the way i liked the BIG NEWS theme. Don’t have money to buy at the moment surely will add it to my collection soon… chao

  12. ymm0t left a comment on February 21, 2010 at 4:40 am |

    Thanks! Will bookmark this.. πŸ™‚

  13. atoranga left a comment on February 10, 2010 at 3:35 pm |

    thank you, you solved my problem

  14. Irfan left a comment on November 7, 2008 at 8:05 am |

    I like category more than tag.

  15. Molli left a comment on October 1, 2008 at 9:24 am |

    Thank you so much for this. I’ll be bookmarking it for future reference for a band’s website I’m putting together. This little tip will come in extrememly handy, I think. Thanks again for posting it.

  16. Raol left a comment on September 18, 2008 at 1:54 pm |

    Thanks.. i was really in need of it…!

  17. fedmich left a comment on May 15, 2008 at 10:33 pm |

    Thanks, great timing as I need this one now.

  18. Sarah left a comment on March 31, 2008 at 6:36 am |

    Great tutorial! I have been looking for this from many days. Thanks for sharing.

  19. mael majid left a comment on March 1, 2008 at 11:24 pm |

    thanks.. i’ll put in on http://www.downloadbokep.cn

  20. }Ja{???? left a comment on February 1, 2008 at 7:20 pm |

    oh~thankyou, i found you, is so useful

  21. moDesignz left a comment on January 14, 2008 at 2:19 pm |

    hi…I need to be able to display a sort of “featured design” section on the front page of my website.

    I was thinking maybe I put a code that shows the latest post which is taking out the codes for the title, meta data and content out of the loop and putting them alone to show only one post which is the latest. I want to do this for a particular category and add a post to that category everytime I want to suggest a featured design.

    But I also want to hide it. I mean hide the category with the “featured designs” so that it doesn’t appear in the nav

  22. SeanCHEN left a comment on January 10, 2008 at 4:19 am |

    Thank you very much!!! It helps me a lot!

  23. Emir left a comment on December 16, 2007 at 7:37 am |

    Hi, I was wondering is it possible to show some unique content on specific post? Let’s say I have only 5 posts where I want to add some content but not anywhere else.. Possible??

  24. Dhan left a comment on December 5, 2007 at 11:29 pm |

    Very helpful tip. Thanks

  25. doniek left a comment on December 5, 2007 at 3:52 am |

    Very good tutorial, thx πŸ™‚

  26. cashmarble.com left a comment on December 3, 2007 at 11:09 am |

    Nice tutorial you got there! thanks for sharing

  27. 365Hope.com left a comment on December 3, 2007 at 10:12 am |

    It is interesting. Thank you! Jai. I will try it on my blog (www.365hope.com).

Leave a Comment

Your email address will not be published. Required fields are marked *

What Others Say

BannerJai was awesome to work with. A port of an ASPX/HTML site to Wordpress went seamlessly, and his recreation of our look and feel were fantastic - Kevin Webster

BannerJai is a talented, creative and an enthusiastic web developer who has worked consistently to deliver high quality websites for my businesses - James Eccles

  •   Let’s Talk

    "Thank you for visiting my website! In order to start a project with me, please send me information on your project so I can figure out how best to help you."

    "After your initial contact, I’ll schedule a quick one-on-one session via Skype to review the project and get to know you."
     Request a Quote
Need a Custom Website?

Leave a Feedback

Tell Me About Your Project