• Hi All:

    I am using the “WP_Widget_Archives” widget in my sidebar and it works just fine to list the months of ALL posts in all categories. My issue is that I only want it to list “month links” based on posts in 1 category (#8). Now, on the archives page I have the correct code to only display using in_category(8) which is also just fine but if there is no post, say, for the month of June in cat=8 the “June” link still shows in the sidebar because there are other posts in other categories which (correctly) do not show up on the archives page when the “June” link is clicked. I would prefer NOT to use a plugin and could possibly settle for just displaying “there are no blog posts for “June” instead of a blank page. My loop code is as follows:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php //if (!in_category($excludeCats)) { ?>
    <?php if (in_category(4)) { ?>
    <div <?php post_class(); ?>>
    <h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
    <div class="postauthor">
    <p><?php _e("Posted by", ''); ?> <?php the_author_posts_link(); ?> <?php _e("on", ''); ?> <?php the_time('F j, Y'); ?> &middot; <a href="<?php the_permalink(); ?>#comments"><?php comments_number(__('Leave a Comment'), __('1 Comment'), __('% Comments')); ?></a>&nbsp;<?php edit_post_link(__('(Edit)'), '', ''); ?></p>
     </div>
    <?php the_content(__("Read more", ''));?><div class="clear"></div>
    <div class="postmeta">
    p><?php _e("Filed under", ''); ?> <?php the_category(', ') ?> &middot; <?php _e("Tagged with", ''); ?> <?php the_tags('') ?></p>
    </div>
    </div>
    <?php } ?>
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.', ''); ?></p><?php endif; ?>
    <p><?php posts_nav_link(' — ', __('&laquo; Previous Page'), __('Next Page &raquo;')); ?></p>

    Thanks in advance.

  • The topic ‘list only archives of certain categories’ is closed to new replies.