Support » Fixing WordPress » show archive template based on post category

  • Resolved BSK


    ok, i hope this makes sense!

    on “page 1”, i have a page template set to show all categories & posts, and have a custom sidebar.

    on “page 2” i have a separate page template setup to show only posts from a certain category, and show a different custom sidebar.

    problem is, when you click into a post on “page 2”, it shows the archive page from “page 1” including page 1’s sidebar.

    basically what i’m trying to do is show a certain archive template based on the post category. is this possible?


Viewing 6 replies - 1 through 6 (of 6 total)
  • A link to your site would probably help to clarify the problem.

    hi esmi – the content for “page 2” is not published yet.

    the site is here.

    I’ve created a separate page (page 2) that only shows posts from one category and shows a different sidebar. the only thing i’m stuck on is when you click into a post on page 2, it shows the default archive page (with the wrong sidebar). How can tweak archive.php to show the correct page template based on the category?


    Can you confirm that your post links are leading to an archive page? Or did you mean single post page?

    ah, yes it is a single post page (single.php).

    I think using the in_category conditional in single.php would help. Something like:

    if( in_category('B') ) get_sidebar('b');
    else get_sidebar();

    where B is the name of your special category and your custom sidebar is called sidebar-b.php.

    thanks so much! i’ll give this a shot and let you know if it works.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘show archive template based on post category’ is closed to new replies.