WordPress.org

Ready to get started?Download WordPress

Forums

Excluding Archive & Category Widgets from Pages (2 posts)

  1. KIntheHouse
    Member
    Posted 6 years ago #

    Hi,

    Is there way to exclude Archives & Categories widget from showing up in the Page sidebar? I want them to show up only in the blog posts but not the pages.

    Thanks in advance.

  2. Clicknathan
    Member
    Posted 6 years ago #

    Assuming you have more widgets than just the Archives & Categories ones you're referring to, you could do the following:

    1. Remove the two widgets in question and replace them with actual code in your sidebar. The code to add Archives is here and Categories is here.
    2. You should end up with some code that looks something like:
      <li><?php wp_list_categories(); ?></li>
      <li><?php wp_get_archives(); ?></li>
    3. You'll then want to use conditional tags to tell WordPress not to show that information on your Pages. So you'll add some code around the above code, ending up with something like:
      <?php if (!is_page()) { ?>
      <li><?php wp_list_categories(); ?></li>
      <li><?php wp_get_archives(); ?></li>
      <?php }  ?>

    Those various <li> bits are just examples of what you might see in the default template, and you may want to change them for your own theme. Hope that helps!

Topic Closed

This topic has been closed to new replies.

About this Topic