[resolved] Excluding Category From Main Page? (9 posts)

  1. deat
    Posted 10 years ago #

    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?

  2. BPartch
    Posted 10 years ago #


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

  3. deat
    Posted 10 years ago #

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

  4. BPartch
    Posted 10 years ago #


    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. :)

  5. deat
    Posted 10 years ago #

    <!-- 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!

  6. jeremytai
    Posted 10 years ago #

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

  7. Rich's modified Category Visibility plugin makes this sort of thing a whole lot simpler: http://ryowebsite.com/?p=46

  8. jeremytai
    Posted 10 years ago #

    Sweet plug-in! Works like a charm.

  9. deat
    Posted 10 years ago #

    Thank you! That worked. :) Sorry for the bother!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.