WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] exclude a category from query posts (5 posts)

  1. oldbag66
    Member
    Posted 5 years ago #

    hi, im making my own dynamic sidebar and i just want to exclude a category from this script, any help would be appreciated:

    <div class="widget">
    <?php query_posts('showposts=10'); ?>
    <li>
    	<h3>Latest News</h3>
    	<ul>
    		<?php while (have_posts()) : the_post(); ?>
    		<li><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></li>
    		<?php endwhile; ?>
    	</ul>
    </li>
    </div>
  2. MichaelH
    Member
    Posted 5 years ago #

    The template tag, query_posts(), has a cat=-7 argument. Replace the 7 with your category ID.

  3. oldbag66
    Member
    Posted 5 years ago #

    ok that makes sense, i actually need to exclude it from this code (sorry my mistake) and not sure how to add the cat exclusion
    <?php wp_list_categories('show_count=1&title_li=<h3>News Categories</h3>'); ?>

    i tried this but it doesnt work, am i close!:

    <?php wp_list_categories('cat=-13&show_count=1&title_li=<h3>News Categories</h3>'); ?>

  4. MichaelH
    Member
    Posted 5 years ago #

    The template tag, wp_list_categories(), uses an exclude= argument (with NO minus sign).

    <?php wp_list_categories('exclude=13&show_count=1&title_li=<h3>News Categories</h3>'); ?>
  5. oldbag66
    Member
    Posted 5 years ago #

    thats great thank-you very much.

Topic Closed

This topic has been closed to new replies.

About this Topic