Support » Fixing WordPress » clear archives of excluded categories

  • Hi
    I’m excluding some categories in archive.php using this code ….

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<?php if (!in_category(23,10,17,14,11,13,12,7,28,22,29,27,26,21,16,15,19,20,25,18,24,8,9,33,32,34,35)) { ?>
        <h5><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a> &nbsp; <?php the_time('F j, Y'); ?></h5>
        <?php } ?>
      <?php endwhile;?>

    It seems to be half working. The months still show up in the archive widget and the highlighted days in the calendar. When I click on these links I get a blank white page. How can I destroy these links completely? I’ve tried resetting the permalinks but it did nothing.


Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    So the problem is the widgets are showing months and highlighting days related only to posts with categories that you wish to exclude?

    If so, you need to change the results the widgets see instead of just filtering what is sent out for the archive page. For the archive widget, it calls wp_get_archives(). You can alter the query used by hooking the filter ‘getarchives_where’.

    For the calendar widget, it uses get_calendar(). Unfortunately, there is no handy filter to hook. The query is hard coded. The clean way to get your desired results is to create a custom version of get_calendar() and a custom calendar widget which would call your special version. Then replace the default calendar with your special one from the widgets admin panel. There’s a dirty hack that is much easier, but a bad idea.

    The blank white page is the result of some PHP error, which hopefully will be a non-issue if you get rid of the offending links.


    I’m not bothered about showing the Archive widget, but I’d like to have the calendar. I think I have two problems. First, the calendar is highlighting days that contain only posts from excluded categories. Second, the blank white pages. It looks like they’re showing even if I click calendar days that contain posts from non-excluded categories, so I must have an error somewhere.

    I’m a WordPress beginner and to be honest I’m not sure where to start with your suggestions. I’ll have to do a little studying.

    Thanks for the help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘clear archives of excluded categories’ is closed to new replies.