Forums

[resolved] Works for Category...Need it to do same for pages (3 posts)

  1. Storyman
    Member
    Posted 4 years ago #

    What the code below does is when a category is selected it loads a particular sidebar based on the parent category. It is working fine (let me know if you see any deprecated code.)

    Now the same thing needs to be done for pages, so when a particular page is loaded a particular side bar needs to be loaded.

    Would appreciate help in converting/creating code that determines the page ID, then loads the appropriate sidebar. This time though it needs a if/else condition since the sidebar # corresponds to the categories and not the pages.

    <?php
    $cat_object = $wp_query->get_queried_object();
    $cat_parent = $cat_object->category_parent; ?>
    <?php include ('sidebar'.$cat_parent.'.php'); ?>

  2. Chris_K
    Member
    Posted 4 years ago #

    You'll probably start with Conditional_Tags. See this sub-section?
    http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page

  3. Storyman
    Member
    Posted 4 years ago #

    HandySolo,

    Thanks. Just what I needed.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags