WordPress.org

Ready to get started?Download WordPress

Forums

Creating a Seperate Sidebar for each page (9 posts)

  1. garvinmusic
    Member
    Posted 9 years ago #

    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?

  2. Mark (podz)
    Support Maven
    Posted 9 years ago #

    Yup - include the sidebar in the template itself.

  3. Jinsan
    Member
    Posted 9 years ago #

    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.

  4. garvinmusic
    Member
    Posted 9 years ago #

    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?

  5. Jinsan
    Member
    Posted 9 years ago #

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

    http://codex.wordpress.org/Customizing_Your_Sidebar
    http://codex.wordpress.org/Conditional_Tags

  6. garvinmusic
    Member
    Posted 9 years ago #

    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?

  7. Kafkaesqui

    Posted 9 years ago #

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

  8. garvinmusic
    Member
    Posted 9 years ago #

    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"?

  9. Kafkaesqui

    Posted 9 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.