WordPress.org

Ready to get started?Download WordPress

Forums

_Really_ exclude a category? (9 posts)

  1. michaelc
    Member
    Posted 9 years ago #

    I'm setting up a fairly complex site that separates "articles" (in a gazillion categories) from "news" (its own category). News will appear as a list of bulleted post titles either under the first front-page post, or on the sidebar of other pages (thanks to aggrss!).

    Using the info at http://codex.wordpress.org/The_Loop, I easily excluded the news from the front-page post listing, but unfortunately, the news category's articles still appear in the RSS feed for the front page.

    Is there a fix/hack anyone can think of?

  2. Kafkaesqui

    Posted 9 years ago #

    The various syndication files (wp-rss.php, wp-rss2.php, wp-atom.php, and wp-rdf.php) sport a version of The Loop that you can make use of in the same way you've done on your front page.

  3. michaelc
    Member
    Posted 9 years ago #

    Thanks. Unfortunately, if I use the code in the RSS2 loop, it has the side effect of not showing that category's articles even on the News category page's feed - that is, my bulleted News links disappear from the front page, because aggrss was pulling them from /category/news/rss2/.

    I'm guessing there needs to be another conditional added in to prevent that - and that's where my custom coding skills start to break down.

    A side question: instead of using aggrss to pull internal links, is it possible to use an internal function like get_archives to pull up posts from just one category?

  4. Kafkaesqui

    Posted 9 years ago #

    Something like get_archives() focuses on posts by date, and spends no time thinking about categories. Anyway, this will work in your rss loop:

    <?php if ( (CATNUM == $cat) || !(in_category(CATNUM)) ) : ?>

    Just replace CATNUM (both) with the numeric ID of the category you wish to exclude from the main rss feed.

  5. michaelc
    Member
    Posted 9 years ago #

    Thanks again. That seems to nuke my RSS2 feeds entirely, though.

    To make sure I have the semantics right, I delete the word CATNUM and replace it with the number 6 (News is category 6). No other modification - I tried single quotes on each/both, just to see - and the spacing remains identical to the above. I paste it into wp-rss2.php immediately below the loop start (and immediately above the "item" tag). I do not paste in the previous code I had been using (although I did try it both ways).

    Did I get that right? (I'm hoping I missed something, because then it'll be easy to fix.)

  6. Kafkaesqui

    Posted 9 years ago #

    You would need to close the if statement as well, with a:

    <?php endif; ?>

    Right after the closing </item> tag.

  7. michaelc
    Member
    Posted 9 years ago #

    Ah, perfect!

    Thanks again, again. This was the last hurdle to getting the site up. (Well, having the poll plugin updated for 1.5 would help too, but it isn't essential.)

  8. nuglops
    Member
    Posted 9 years ago #

    Pardon me for being dense, but I'm lost...

    I understand the loop, it's the same for basically every piece of blog software out there. Where I'm lost is in creating the Template Tag. Anytime I try and use the <?php if ( !(in_category('3')) ) { ?> it errors out.

    I'm using the exact code on the site just replacing the category number with the one I want to exclude:

    <?php get_header(); ?>

    <div id="content" class="narrowcolumn">

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

    <!-- The following tests if the current post is in category 3. -->
    <!-- If it is not, the code within The Loop is executed as normal. -->
    <!-- If it is, nothing is done until the next post is processed. -->
    <?php if ( !(in_category('36')) ) { ?>

    <div class="post">

    <h2>"><?php the_title(); ?></h2>

    <small><?php the_time('F jS, Y'); ?></small>

    <div class="entry">
    <?php the_content(); ?>
    </div>

    <p class="postmetadata">Posted in <?php the_category(', '); ?>
    </div> <!-- closes the first div box -->

    <?php } ?> <!-- Close the if statement. -->

    <?php endwhile; else: ?>
    Sorry, no posts matched your criteria.
    <?php endif; ?>

    </div>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>

    In a new page entry and instead of working like I would assume or even just displaying all categories it's listing the php code. Am I missing something?

    http://nuglops.com/blog/?page_id=1046

  9. nuglops
    Member
    Posted 9 years ago #

    Nevermind, it works amazingly well when you RTFM :-)

    http://faq.wordpress.net/view.php?p=55

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.