WordPress.org

Ready to get started?Download WordPress

Forums

[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:
    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

  2. Eric Amundson
    Volunteer Moderator
    Posted 6 years ago #

    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.

  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 6 years ago #

    Glad you got it working!

  5. kremo5le
    Member
    Posted 5 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?

    THANK YOU!

    k.

  6. lexpression
    Member
    Posted 5 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