• OK, I know how to use get_posts to get posts from a single category. Got that OK…. Now what I want to do is EXCLUDE a category from the listing.

    Here’s what I’m up to, on my page, I want the first post to be the latest post from a particular category – that’s the part I get, no problem. This will be me welcome/site news/upcoming stuff.

    The next thing I want is the last post, UNLESS it’s in the category that is display above. So I want to exclude that category. Otherwise I get the same post listed twice.

    I suppose I could put all my postings, except for the news ones, into a “General” category, then draw from that…. just seems like a kludge….. but probably would work….

    If any one else has any ideas, I’m open to suggestions.

    -tg

Viewing 9 replies - 16 through 24 (of 24 total)
  • I’m wanting to do something like this as well. I want to display the titles of my 10 most recent posts in the SIDEBAR. Right now, I’m using:

    <?php get_archives(‘postbypost’, 10); ?>

    But I want to exclude category 88. Any idea of how to do this in the sidebar? Thanks in advance…

    Well, I don’t know if this was the easy way or the hard way of doing it, but I got this to work with the following code:

    <li id="Recent">
    	<h2>Recently Written</h2>
    <ul>
    <?php $temp_query = $wp_query; query_posts('showposts=10&cat=-88'); ?>
    <?php while (have_posts()) { the_post(); ?>
    <li><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to &ldquo;<?php the_title(); ?>&rdquo;"><?php the_title(); ?></a></li>
    <?php } $wp_query = $temp_query; ?>
    </ul>
    </li>

    Look for this on your main theme index page:
    <?php if (have_posts()) : ?>

    Insert this right before (or above) it:
    <?php query_posts('cat=-49'); ?>

    Change the category ID to whatever it is you want to exclude.

    This plug-in, Recent Posts +, worked for me. No coding necessary. It lets you set an option to exclude as many categories/authors as you want.

    Is it possible to exclude categories by name an NOT by id?

    thanks
    yavuz

    Yuchi,
    your code works great! I had the same problem with the next and previous link and now with your piece of code it’s gone…many thanks!

    What exactly is the difference between using

    <?php if(is_home()) {query_post("cat=-39");}?php>

    and what you gave us?

    Stealth Publish is a Plugin from coffee2code which does the same with a custom field.

    But I prefer the method with the hack in the index file. It’s clean short and no use for additional Plugin.

    Lets compare…

    <?php if (is_home()) {
      query_posts($query_string . "&cat=-33");
    } ?>
    <?php if(is_home()) {query_post("cat=-39");}?php>

    firstly, there’s supposed to be an ‘s’ in query_posts, secondly, adding the $query_string preserves the pagination information as derived from the URL you’re using at the time. The second example is missing a few vital parts, not the least of which is that niggly ‘s’.

    I think this is related…
    I want to display the 3 most recent excerpts within a specific category
    following a static page post.
    I have a separate template for this page (which only contains content in this category, 7) so I’m coding it in the template just following the post.
    I’ve found some of the code but am not figuring how to put it together.

    thank you in advance for your help

Viewing 9 replies - 16 through 24 (of 24 total)
  • The topic ‘How to exclude a category…’ is closed to new replies.