WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Exclude a category in home page latest posts (5 posts)

  1. johndove523
    Member
    Posted 1 year ago #

    Hi, see url http://testing.backstageweb.net/

    On the home page, the text under the photo is a post with a category of "home page" (ID=4). In the "recent blog posts" box on the left, I don't want the "home page" category post to show up in that list. How do I need to modify this code:

    <ul>
    	<?php query_posts(array('showposts' => 2, 'order' => 'dec')); while (have_posts()) { the_post(); ?>
    	<li class="date"><?php the_time('F j, Y'); ?></li>
    	<li class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    	<?php } ?>
    </ul>
  2. Thor Brink
    Member
    Posted 1 year ago #

    You need to add the "cat" attribute to the query_posts argument array.
    The updated could should be:

    <ul>
    	<?php query_posts(array('showposts' => 2, 'order' => 'dec', 'cat' => -4 )); while (have_posts()) { the_post(); ?>
    	<li class="date"><?php the_time('F j, Y'); ?></li>
    	<li class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    	<?php } ?>
    </ul>

    The '-4' means that the category with an ID of '4' should be excluded.
    More on this can be found in the WordPress Codex.

  3. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

  4. johndove523
    Member
    Posted 1 year ago #

    Thanks guys! Worked like a charm.

  5. johndove523
    Member
    Posted 1 year ago #

    Thanks also for those specific Codex topics. It's difficult to know what to ask for when you don't know the nomenclature.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.