WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] show archive template based on post category (7 posts)

  1. BSK
    Member
    Posted 4 years ago #

    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?

    thanks!

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    A link to your site would probably help to clarify the problem.

  3. BSK
    Member
    Posted 4 years ago #

    hi esmi - the content for "page 2" is not published yet.

    the site is here.

    http://resources.lsaweb.com/

    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?

    thanks!

  4. esmi
    Forum Moderator
    Posted 4 years ago #

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

  5. BSK
    Member
    Posted 4 years ago #

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

  6. esmi
    Forum Moderator
    Posted 4 years ago #

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

    <?php
    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.

  7. BSK
    Member
    Posted 4 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.