Exclude categories from wordpress frontpage

You may also like...

42 Responses

  1. Rachel says:

    Thank you so much, thinkdj! This code actually works in WP 2.3.2, whereas all the other tricks I've tried – those published in the codex – do not. They reordered all the posts on my home page, displaying the oldest first – not exactly what I wanted…

    Thanks!

    Rachel

  2. thinkdj says:

    U're welcome Rachel 🙂

  3. Rachel says:

    Hi, thinkdj,

    I have a couple of questions:

    1) Do you know if there's a way to only include posts if they have categories in addition to the excluded one(s)?

    2) How do I exclude the posts from my "Recent Posts" list on the sidebar? (I am using the My_Link widget for that, see this page for more info on that).

    Thanks so much!

    Rachel

  4. Rachel says:

    Hi, thinkdj,

    I think I might've found a solution for #2:

    http://blue-anvil.com/archives/create-a-wordpress

    🙂

    Thanks!

    Rachel

  5. stim says:

    Hi,

    I've tried every which way and it won't work for me.

    Here's what I did:

  6. Jasmine says:

    Thanks for the tip. I was looking for a plugin to do the job, but now seems it's easier to just hack the index.php file. Quicker and cleaner. 🙂

  7. pixie says:

    Do you know how this would work for WordPress 2.5.1, in my K2 theloop.php I have

    and so have made it

    to no avail….

    I have tried countless plug-ins, hacks and code but yours is the only site actually implementing it, I'd be very grateful for any help.

    Cheers, Emma 🙂

  8. Rachel, this worked for me:

    cat_ID == '12') continue;

    } ?>

    The result is that any posts that have only category 12 will be ignored.

  9. Trying again:

    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ? >

    <?php if (is_home()) {

    $categories = get_the_category();

    if (count($categories) == 1 && $categories[0]->cat_ID == '12') continue;

    } ?>

    • Supriya says:

      What is I have to exclude more than 1 category & that too by name ?? I tried this to exclude 1 category :

      cat_name == 'Videos') continue;

      } ?>

      But what for excluding more than 1 categories??

  10. Rachel Buddeberg says:

    Thanks, Rafael! I'll try that…

  11. Fendy Ahmad says:

    Although it'd work skipping the unwanted category but it will not change the number of "Previous Post" pagination at the bottom.

    Have any idea how to modify that?

  12. Peter says:

    Hey,

    I don't know if it is still usefull for you or that it is just a feature of the TMA theme, but with the code beneath the two categories Asides and Featured are removed from the resulting list.

    <code>

    get_var("SELECT term_ID FROM $wpdb->terms WHERE name='Asides'"); ?>

    get_var("SELECT term_ID FROM $wpdb->terms WHERE name='Featured'"); ?>

    <?php $the_query = new WP_Query('cat=-' .$catid. ',-' .$catid2. '&showposts=1&orderby=post_date&order=desc');</code>

  13. To exclude a category from the loop on the front page, find this code:

    and change it to this:

    This will exclude posts in category number four from being displayed on the front page.

  14. Matias says:

    Excelent… simple and efective. Thank you thinkdj

  15. joe says:

    why not just use these plugins, find them in google by typing: "wordpress exclude category plugin"

  16. Arnold96 says:

    Organised by Management Forum. ,

  17. Gangster95 says:

    It would be condemnable on consequentialist grounds, if there are feasible alternative arrangements that would bring about more mixing of people, a better fit of complementary types in productive schemes of cooperation, and better outcomes for people according to the right standard for assessing outcomes. ,

  18. bon says:

    how about in archive? how can i hide the selected category?

  19. Mega Rick says:

    Cool, thanks! Exactly what I needed.

  20. Fantastic information in your post, I saw this report on television yesterday about this same thing and since I am getting married in two weeks and the timing could not have been better! thanks for the info!, I have bookmarked, thanks Rayford Mahler

  21. Worked like a charm on my site Best Date Night Ideas! This solution did exactly what I wanted it to. Thanks a ton for posting this.

  22. พร&#3632 says:

    We enjoy this site given and it has presented me several sort of inspiration to have success for some good reason, so thank you.

  23. Martin says:

    Thx! Work great!

  24. The easier way to accomplish the same thing is to use this plugin.

    http://ryowebsite.com/wp-plugins/category-visibil

    This allows MUCH more flexibility in where your posts are shown.

  25. Alan Dove says:

    At least in the current version of WordPress, you can use the category name instead of the number, e.g.:

    <code>if (is_home()) if (in_category('uncategorized')) continue;</code>

    Also, if you copy and paste the code in the original post, be sure you change the curly back-ticks to regular straight single quotes, or it won't work.

  26. I know this is genuinely boring and you are skipping to the next comment, but I just wanted to throw you a big thanks – you cleared up some things for me!

  27. Online Blend says:

    There is a problem with this, let's say the homepage is supposed to show 10 posts, if 5 of those are in the excluded category the homepage will only show 5 where as the expected behaviour is to continue getting more posts until 10 non-category posts can be shown. How can this be accomplished?

  28. Movies says:

    I used this code. it is actually good. But it does not effect the subcategories of a category.

  29. juste put this : &exclude=5 (5 is the ID of the category what we want to exclude)

    Exemple : wp_list_categories('title_li=&exclude=5&orderby=id');

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.