WordPress.org

Ready to get started?Download WordPress

Forums

hiding categories on the front page (6 posts)

  1. chigh
    Member
    Posted 8 years ago #

    This seems to work pretty well, but is this still the best method of hiding categories on the front page?

    http://codex.wordpress.org/FAQ_Layout_and_Design#How_do_I_hide_a_category_from_the_front_page_index.php.3F

    I ask because in the options, my-hacks.php is called "legacy".

  2. petit
    Member
    Posted 8 years ago #

    Well, that seems a bit old. I think a better bethod is to exclude a category from the front page by introducing the exclusion directly inside the loop of the theme's index.php

    Th loop starts something like this:
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    To exclude category 4 from the front page, 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.

  3. chigh
    Member
    Posted 8 years ago #

    Thanks, I will try that out. I knew that the my-hacks.php thing was old, but haven't seen anything else which was comparable.

  4. jwalters
    Member
    Posted 8 years ago #

    chigh, did that work for you? I am looking to do the same thing.

  5. petit
    Member
    Posted 8 years ago #

    A full explanation of the method I tried to introduce can be found in The Loop, here.

  6. chigh
    Member
    Posted 8 years ago #

    Thanks for all the info. I haven't actually implemented this yet. I've been quite busy.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags