Support » Fixing WordPress » Exclude categories using the wp_widget_archives widget

  • Resolved bridgemanusa

    (@bridgemanusa)


    Hi All:
    I am using the wp_widget_archives() function to list my post archives by month, which works just fine as far as displaying the months as links:

    <?php the_widget('WP_Widget_Archives'); ?>

    When I select a month, the archives page (when no changes are made to the standard query call) returns all posts for the requested month are shown

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

    However, when I try and filter out categories (on the archive page), I get all posts no matter what (no more posts by month). I have tried the following (give me all posts from Cat 8 and children):

    <?php query_posts('cat=8'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    and (get me all posts excluding cat 11,14,25):

    <?php query_posts('cat=-11, -25, -14'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    Am I doing something wrong in my query or is there another way to call wp_widget_archives to exclude the categories I do not want shown? Should I not be using wp_widget_categories at all? I did some searching in other posts that may have indicated a limitation of wp_widget_categories but was unsure if this was the case in 3.0.

    Any insight is greatly appreciated.

Viewing 1 replies (of 1 total)
  • Thread Starter bridgemanusa

    (@bridgemanusa)

    Well, I found a solution but not on the WP forum.

    This seems to work:

    <?php $excludeCats = array(1,5,4);
       if (have_posts()) : while (have_posts()) : the_post();
           if (!in_category($excludeCats)) { ?>
           ...do stuff...
    <?php } endwhile; endif; ?>

    Hopefully that helps someone else. Thanks for looking.

Viewing 1 replies (of 1 total)
  • The topic ‘Exclude categories using the wp_widget_archives widget’ is closed to new replies.