[resolved] Exclude category from archives navigation (6 posts)

  1. I have two posts categories in my site, news and jobs.

    On my side bar, I want to display the following navigation:

    I've been using the following:

    <li><a href="">NEWSROOM</a>
    		<?php wp_get_archives('type=yearly'); ?>

    This works, but when I click on the link to the 2008 archives, the jobs posts also appear. Is there a way to get_archives from only one category?


  2. Eric Amundson
    Volunteer Moderator
    Posted 8 years ago #

    Check this:

    I know there's a way to do it using php, but this may make it easier.

  3. Thanks sewmyheadon, I looked at the plugin, but that plugin wasn't compatible with the option to show by year.

    Instead what I did in my archive.php file is add a simple if statement to omit the posts from the jobs category, since these will never be archived.

    <?php while (have_posts()) : the_post(); ?>
      	<?php if (!in_category(3)) { ?>
        <h5><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a> &nbsp; <?php the_time('F j, Y'); ?></h5>
        <?php } ?>
      <?php endwhile; else: ?>

    And that works perfectly!

  4. Eric Amundson
    Volunteer Moderator
    Posted 8 years ago #

    Glad you got it working!

  5. kremo5le
    Posted 7 years ago #

    Hey guys,

    Where do you put that code? I'm trying to exclude a category form the "Archive" widget, yet I cannotmake it to work. I really don't know where to drop that code within the archive.php.

    Could you let me know where exactly?



  6. lexpression
    Posted 7 years ago #

    Find the 'while' loop in the archive.php page and replace it with the above code. However, remove the 'else:' right after the 'endwhile;'

Topic Closed

This topic has been closed to new replies.

About this Topic