WordPress.org

Ready to get started?Download WordPress

Forums

exclude post from main index (7 posts)

  1. affysucks
    Member
    Posted 7 years ago #

    Is there a way to exclude posts from a particular category to appear in the main part of the site?

  2. Glenn Ansley
    Member
    Posted 7 years ago #

    Do you mean the on any page or just the home page?

    If the home page, copy your index.php and name it home.php and edit the loop.
    If any page, edit the loop in your index.php

    Check out this section for the codex page on the_loop: http://codex.wordpress.org/The_Loop#Exclude_Posts_From_Some_Category

  3. rudolf45
    Member
    Posted 7 years ago #

    It never hurts to search:
    http://wordpress.org/search/exclude+category+main+page?forums=1
    (there are several plugins doing it...)

  4. affysucks
    Member
    Posted 7 years ago #

    It did do a search but it came up with a "category visibility" plugin by Rich Hamilton.

    It does the job just fine but I want exclude all entries on a particular category from all pages of my website but the entries i want to hide seems to pop up under "most recent entries" and under calender

    All I want to accomplish is to make all entries on a particular category to not appear on all pages of my site, unless they typed in the exact permalink of the hidden entry on the address bar.

    Any suggestions?

  5. motocafe
    Member
    Posted 6 years ago #

    Seems like this should be a standard WP feature...

  6. RachelAB
    Member
    Posted 6 years ago #

    For excluding posts in the Recent Posts list, check out this widget:

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

    I haven't tried it yet but it sounds promising! You'll have to combine it with code that excludes the category from the main page (see blepoxp or rudolf45 posts or http://blogulate.com/content/exclude-categories-from-wordpress-frontpage/ BUT note that the posts are still counted even though they're not shown), so it's a bit of a pain but...

  7. blogsnapper
    Member
    Posted 6 years ago #

    Another way of excluding more than one category from the home page is to add a small piece of code in your template (index.php etc).

    Look for (should be somewhere between line 1-20):
    <div class="post" id="post-<?php the_ID(); ?>">
    Insert this directly above:
    <?php if ((in_category(1) || in_category(2)) && is_home() ) continue; ?>

    Explanation: The code in this example looks for posts from categories with id 1 and 2. If they exist and the visitor are on the home page (is_home), they are hidden.
    If the visitor are viewing another category page than home, the posts will be visible.

    Exclude one category only?
    If you only want to exclude/hide one single category from the home page, use this code instead:
    <?php if (in_category('1') && is_home() ) continue; ?>

    Remember!
    Hiding a category won't make it invisible to the system. If you have specified to show 10 posts in a category page and 3 of the posts are hidden (as described above), the total amount of visible posts will be 7. The system will not add three new posts from the archive since it consider it allready shows 10 (as defined in dashboard). More advanced code is needed to accomplish this.

    This solution has been tested in WordPress 2.5

    Enjoy,
    //Blogsnapper

Topic Closed

This topic has been closed to new replies.

About this Topic