Support » Fixing WordPress » Excluding Category From Main Page?

  • Resolved deat


    I want to exclude a certain category from my main page. I looked in the Docs and found this:

    If you need to exclude a category from the front page, you can place code that does the exclusion inside The Loop of your theme's index.php file.

    The Loop starts something like this:

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

    To exclude category 4 from the front page, just inside The Loop, add this condition :

    <?php if ( !(in_category('4')) || !is_home() ) { ?>
    <!-- Output the post here -->
    <?php }>

    This means that if on the front page, the post will be presented if it's not in category 4. On pages other than the front ( home ) page, all posts are presented.


    But I’m not sure where exactly to put their piece of code. Any suggestions?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hello

    That would go in the index.php file located in wp-content/themes/the-theme-you-are using-folder

    I know it goes into the index.php, but where in that file does the code go?


    It should go right after the opening loop tag:

    Opening Tag: <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php if ( !(in_category(‘#’) && is_home()) ) { ?>

    Just change the # with the category # you want to exclude.

    Hope it helps. 🙂

    <!-- begin posts -->
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <ul class="newsDate">
    <li><?php the_time('F jS, Y') ?> </li>
    <p><?php the_content('Read the rest of this entry &raquo;'); ?></p>
    <div class="newsFooter">
    <li class="category"><?php the_category(', ') ?></li>
    <li class="comments"><?php comments_popup_link('No Comments', '(1) Comment', '(%) Comments'); ?></li>
    <?php //trackback_rdf(); //commented out for xhtml validation?>
    <!-- end of posts -->

    That’s part of my index.php code. see how the loop is split into two? I tried putting it after both, and then in between it. Niether worked. Is there certain spacing i should do?

    Thank you!

    let me know if you get this going. i’m trying to do the same thing.

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Rich’s modified Category Visibility plugin makes this sort of thing a whole lot simpler:

    Sweet plug-in! Works like a charm.

    Thank you! That worked. 🙂 Sorry for the bother!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Excluding Category From Main Page?’ is closed to new replies.