Support » Themes and Templates » Creating a Seperate Sidebar for each page

  • Basically, the effect I want is that each page I create, have the ability of creating it’s own template. That’s the easy part. The hard part is, having each page template refer to a different sidebar template. Anyone know how to achieve this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Mark (podz)


    Support Maven

    Yup – include the sidebar in the template itself.

    what I’ve learnt is that you can either have one sidebar.php that calls different data, but uses if/else statements or you can create lots of sidebar.php files and then call that based on the cat. I’m finding if/else statements a much cleaner way to manage this. The codex should have some examples (though they could do without the clutter of explanation within the code, very messy) of if/else.

    So, in theory, you could have one sidebar.php file that says:

    if cat x then display this data in the sidebar
    else if cat y then display this data in the sidebar
    else display standard data in the sidebar

    The easiest, and pretty horrible way, is to create sidebar-1.php, then sidebar-2.php and have the different data in each one, and call them in the page.

    Well, is there a template code out there that would allow me to create a page that has a template that would make it an acting sidebar (such as with includes, etc?). Meaning, I don’t have to straight code a sidebar in each template, I can just include the page, that I created with WordPress’s Page Creator section, and it will shape it necessarily?

    Not sure what you mean as your question is a little…messy? Try and break it down into bits. Meanwhile, try this:

    ok. apologies 🙂 basically, when you create a new page, you have the option of choosing your template. which is great, for lets say, if i wanted to do the whole, each page has its own sidebar. BUT, what if I wanted to create a sidebar using the create a page feature. i’d create a page, with the content of that sidebar, then choose “sidebar” as the template, which I would have to create, of course.

    that’s all easy. what the question is, if i were to do something like this, could i call it in my regular page template. such as now, if you want to call the sidebar, you’d code it:

    <?php get_sidebar(); ?>

    could i use a similar code to call a specific sidebar? if so, how?

    <?php include(TEMPLATEPATH . '/my-sidebar.php'); ?>

    TEMPLATEPATH is a WP constant that defines the active theme directory. Just change my-sidebar.php to the name of your sidebar template file.

    brilliant. ok, then here is a thought. cause that answered half of my question. could i use that same idea, with, let’s say “/?page_id=10” as the include, instead of “/my-sidebar.php”?

    No, since it’s just a query uri (to a Page’s content in the database) and not an actual document you’re trying to include. If you want to include a particular Page’s content within a template, set up a loop that’s initialized by query_posts() (you can find some helpful links on that here), or use a plugin like my Get-a-Post.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Creating a Seperate Sidebar for each page’ is closed to new replies.