Change Theme

Change Font Size

decrease size increase size

Search


Dynamic Sidebar


In this tutorial, you will learn how to make different side bar for each individual page of your website.

Introduction

Let’s begin by listing the files that we will be needing:

  • sidebar.php – already in the themes folder
  • sidebar_main.php – will be creating
  • sidebar_pages.php – will be creating

Let me explain what each of the files above will be doing.

sidebar.php:
This is your original sidebar. This is what I call the “remote control”. This page will call up either sidebar_main.php or sidebar_pages.php; depending on what page you are on.

sidebar_main.php:
This file will show up on your index.php.

sidebar_pages.php:
This file will be called up when you visit one of your pages.

Step One

Now, it is time to start coding your very own dynamic sidebar.

Open: sidebar.php

  • Copy all of the codes.
  • Open Notepad.exe or any other coding program that you may use
  • Paste the codes in there
  • Save it as sidebar_main.php

Step Two

Open: sidebar.php
Paste the following codes in there:

<div id="sidebar">

<?php if (is_home()) {
include (TEMPLATEPATH . "/sidebar_main.php");}
else {
include (TEMPLATEPATH . "/sidebar_pages.php");
}
?>

</div>

Save it.

You will need to change the id to reflect on your theme’s CSS.

Step Three

Open: Notepad.exe or any other coding program.
Paste the following codes:

<?php if (strstr($_SERVER['REQUEST_URI'], '/YOUR DIRECTORY HERE/')) { ?>
This is the side bar on your profile page. ADD THE CONTENTS HERE.

<?php } elseif (strstr($_SERVER['REQUEST_URI'], '/YOUR DIRECTORY HERE/')) { ?>
This is your side bar on your domain page. ADD THE CONTENTS HERE.

<?php } ?>

And save it as sidebar_pages.php.

You obviously need to edit /YOUR DIRECTORY HERE/. For example, if your page is called “visitors” then, your directory will be called /visitors.

The coding above it set up for only two pages. If you’d like to create a sidebar for another page, you’ll need to add another include.

You’ll need to include another line of this code:

<?php } elseif (strstr($_SERVER['REQUEST_URI'], '/YOUR DIRECTORY HERE/')) { ?>
This is your side bar on your domain page. ADD THE CONTENTS HERE.

Finish . . .

And you’re done. Upload everything to your themes folder and you should have a dynamic sidebar working.

If you’re stuck, here’s a copy of my dynamic sidebar files as reference.
sidebar.phpsidebar_main.phpsidebar_pages.php

Need Assistance?

If you have any question(s), please don’t hesitate to contact me. I’d be glad to help you out.



Leave a Comment
(will not published)
Bold Underlined Italics Quote Ext Link
:biggrin: :blank: :blush: :confused: :cool: :cute: :dead: :evil: :frown: :ouchies: :secret: :shock: :smile: :stress: :upsidedown: :wink: :yawn: :yell: :yuck: :yummy: :tv: :music: :heart: :drink: :floppy: :ahh: :aww: :duh: :eww: :grr: :hmm: :yay: :wtf: :wow: :umm: :omg: :lol: :huh: :blah: :haha: :hehe: :sigh: :rofl: :pssh: :ouch: :muah: :lmao: :iheartu:
* indicates required field