How to exclude posts of a single category from main listing of your wordpress blog.

As I recently launched this blog I am still trying to experiment with few things, so I enabled Daily and Weekly digests of my tweests in Twitter Tools. Now I still want to have those digests but I don’t like seeing the posts in the main post listing or in feeds. So I decided to hack into wordpress and exclude the “Tweets Archive” category from the main post listing. I had to do bit of research into WordPress Codex and some testing to make it working so I decided to share it here on the blog as well.

  1. Goto your Blog Admin and then goto Categories under Posts.
  2. Click on the Category you want to exclude and then note the Category ID number. You can see the number in the picture below that is shown at the end of the URL in the address below. In my case it was category id 27 which I had to exclude.
  3. How to find the Category ID on your wordpress blog

  4. Goto your WordPress Blog Admin and then goto Editor under Appearance.
  5. Wordpress Blog Admin Appearance Theme Editor

  6. Open the file “index.php” from right column and find the line “<?php if (have_posts()) : ?>”
  7. Wordpress Blog Theme Editor index.php file

  8. Just before that line add following code:
  9. <?php if (is_home()) { query_posts($query_string . "cat=-27"); } ?>

  10. Save the file and you are done.

Congratulations if you have followed till here. This might not be your first WordPress hack or you might have already done the same thing probably using some other method or may be plugin, or you might have learned something new in this short hackorial. Let me know you thoughts or give me some suggestions, I would love to hear from you.

Published by

Hameedullah Khan

VR enthusiast, Cloud Architect, Passionate Programmer and Opensource advocate.

One thought on “How to exclude posts of a single category from main listing of your wordpress blog.”

Leave a Reply

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

CommentLuv badge