Support » Fixing WordPress » Custom sidebar per page

  • Resolved Anonymous

    I am looking at having a custom sidebar per page. I searched and found how to do it per category at

    if (is_category('80')) { 
     include(TEMPLATEPATH . '/sidebar80.php');
    } elseif ( (is_category('81')) {
    include(TEMPLATEPATH . '/sidebar81.php');
    } else {
    include(TEMPLATEPATH . '/sidebar.php');

    but I am not sure which tag and where I should do a similar thing if I want custom sidebars for other pages, like the ‘About’ page (page_id 2 for example)
    Any help is appreciated, thanx 🙂

Viewing 14 replies - 1 through 14 (of 14 total)
  • elseif (is_page('2'))
    // do stuff

    Does that make sense?

    Thanx for the reply, as per the thread link I posted I have category.php (a copy of archive.php) and I am able to include different sidebars for different categories, but putting the is_page code you pasted in there doesn’t affect the About page.

    I am nt sure where to put your code. This doesn’t work:

    if ( is_category('3')) { 
     include(TEMPLATEPATH . '/sidebar-3.php');
    } elseif ( is_category('4')) {
    include(TEMPLATEPATH . '/sidebar-4.php');
    elseif ( is_category('5')) {
    include(TEMPLATEPATH . '/sidebar-5.php');
    elseif ( is_page('2')) {
    include(TEMPLATEPATH . '/sidebar-7.php');
    elseif ( is_category('6')) {
    include(TEMPLATEPATH . '/sidebar-6.php');
    } else {
    include(TEMPLATEPATH . '/sidebar.php');

    Ah! You have the calls to the different sidebars in the page templates and not in sidebar.php. In that case, you’ll want to edit your Page Template. If you include the code I posted last time in your Page Template, it should work (if I’m understanding your situation correctly).

    Yes I edited the page template (page.php) and it works, thanx very much for the support tsguitar 🙂

    Thank you for posting this – I’ve been able to use this code to change the sidebar depending on which page a user visits. This is particularly useful because I have customized “Home” page, a blog, and an online shop – each with heir own needs for different sidebar content.

    Is there an easy way to simply load a single sidebar file without having to include “if” statements?

    I’m sorry for my newb-ness. I am unfortunately not very familiar with php.

    AMAZING!!!! THANKS, after 1 hour i finnaly get it….

    Page_id is visible when you disable permalinks in the URL.
    I whas trying it on the ORDER ID, ofcourse that doesnt work…

    Another great way to do this without bothering with code is Slayer’s custom widgets. It’s a nice widget which allows you to edit where you want sidebars per page

    Great information. A quick question-

    I am looking to do what you all mentioned, short of coding in all the pages for each side bar, How can I tell word press to use side bar 1 for all pages and children pages of topic 1, then use side bar 2 with all pages and children pages of topic 2?

    Site map Example
    -Prent topic 1
    –child a1
    –child a2
    –child a3
    -Prent topic 2
    –child b1
    –child b2
    –child b3

    To have side bar 1 work with all pages for parent topic 1, and have side bar 2 work with all parent topic 2?


    Quick question:

    Does all this still apply to WP 2.7 as well?

    With the advent of pages disappearing from the file list in the editor (& now appearing as (../wp-admin/page.php?action=edit&post=#), does that mean the “is_” statement is now “is_post(‘#’)”?

    Also, which page do I post the php script above in, the page.php or the sidebar.php? I tried both & it’s not working.

    Basically I have 2 of my pages which are about 2 people specifically, and they want to customize their sidebars (favorite videos, music, facebook link, twitter link, etc). George appears a “../wp-admin/page.php?action=edit&post=5”, & Dave (me) appears as “../wp-admin/page.php?action=edit&post=6”, and I want each to direct to bring up sidebar-george.php & sidebar-dave.php (with everything else bringing up the main/primary sidebar). How would a script look like for something like that in WP 2.7?


    Are you guys making any changes to the functions.php file? If not, how are the sidebars showing up in the widget section of your theme?


    Any help is greatly appreciated on this topic.


    I still haven’t been able to figure this issue out, be it because I am editing the wrong document, or there is an error in my coding.

    I have changed my page.php to reflect the following:

    if (is_page(‘5’)) {
    include(TEMPLATEPATH . ‘/sidebar-george.php’);
    elseif ( is_page(‘6’)) {
    include(TEMPLATEPATH . ‘/sidebar-dave.php’);
    } else {
    include(TEMPLATEPATH . ‘/sidebar.php’);

    and I keep getting this error:

    Parse error: syntax error, unexpected T_ELSEIF in (…/wp-content/themes/PRiNZ_BranfordMagazine_latest/branfordmagazine/page.php on line 22

    Any assistance is greatly appreciated.

    In the words of homer simpson…”DOOOH!”
    I was doing the right thing all along.
    I had copied & pasted someone else’s code, but there was a missing “}”.
    Once added, worked like a charm.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Custom sidebar per page’ is closed to new replies.