WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Exclude category from archives navigation

[Resolved] Exclude category from archives navigation

  • Christine Rondeau
    Volunteer Forum Moderator

    @crondeau

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

    On my side bar, I want to display the following navigation:
    NEWSROOM
    2008
    2007
    2006

    I’ve been using the following:

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

    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?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Eric Amundson
    Volunteer Moderator

    @sewmyheadon

    Check this:
    http://wordpress.org/support/topic/130363?replies=5

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

    Christine Rondeau
    Volunteer Forum Moderator

    @crondeau

    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!

    Eric Amundson
    Volunteer Moderator

    @sewmyheadon

    Glad you got it working!

    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?

    THANK YOU!

    k.

    lexpression
    Member

    @lexpression

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Exclude category from archives navigation’ is closed to new replies.