• Hi all,

    I would like the sidebar (more specifically the content inside the sidebar) on the home page to be different from the sidebar on the rest of my site. In my sidebar.php file I have the following:

    <?php include (TEMPLATEPATH . '/sidebar1.php'); ?>
    
    <?php include (TEMPLATEPATH . '/sidebar2.php'); ?>

    I was wondering if I can do something like

    IF IS HOME:

    <?php include (TEMPLATEPATH . '/sidebar1.php'); ?>
    
    <?php include (TEMPLATEPATH . '/sidebar2.php'); ?>

    ELSE:

    <?php include (TEMPLATEPATH . '/sidebar3.php'); ?>
    
    <?php include (TEMPLATEPATH . '/sidebar4.php'); ?>

    Obviously I have to create the sidebar3.php and sidebar4.php files. I don’t know PHP very well so how can I do this conditional statement and will it for the current task at hand?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Yes you can do exactly that.

    <?php
    if(is_front_page()) {
      include (TEMPLATEPATH . '/sidebar1.php');
      include (TEMPLATEPATH . '/sidebar2.php');
    } else {
      include (TEMPLATEPATH . '/sidebar3.php');
      include (TEMPLATEPATH . '/sidebar4.php');
    }

    ?>

    If the sidebar files are not long, the code doesn’t have to be in a separate file either. You can include the code that would otherwise be in the include file in place of an include statement in the IF / ELSE. Or if one is short and the other long, the short could be in the main sidebar file and the longer in a separate file.

    Thread Starter transpersonal

    (@transpersonal)

    Thank You so much stvwlf, that worked great!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Different Sidebar on Different Pages?’ is closed to new replies.