Ready to get started?Download WordPress


[resolved] How to exclude categories from loop? (5 posts)

  1. deko
    Posted 8 years ago #

    When a visitor first arrives at my blog, I only want to display posts in category 1 (the default category).

    All other posts are categorized and can be selected from a nav bar.

    I tried modifying the loop in /wp-contnet/themes/default/index.php:

    <?php if (have_posts() && in_category('1')) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">

    But this does not work.

    Any idea how to accomplish this?

    Thanks in advance.

  2. deko
    Posted 8 years ago #

    Hey, I think I figured it out:

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if (!in_category(1)) { continue; } ?>

    any comments/feedback appreciated...

  3. batdevis
    Posted 8 years ago #

    have a look here:

    You can exclude the category typing
    if (is_home()) {

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    People always trying to reinvent the wheel...

    Category Visibility. It lets you hide categories from the home page, from archives, from search results... Whatever you like: http://ryowebsite.com/?p=46

  5. thebindlestick
    Posted 7 years ago #

    He has a 2.1 version, anyone using this? is there a way to hack this to exclude categories from the list on another page, i.e. right.php instead of sidebar.php?

Topic Closed

This topic has been closed to new replies.

About this Topic