Balkhis - Vision for success

How to add a dynamic sidebar in Wordpress?

 Mar 25, 2008  Syed Balkhi  Web Designs Resources  

Do you ever wonder that you have one sidebar, but you want to display widgets in other places, and they don’t come in with manual codes that you can enter in the page and avoid using the widgets. Well there are some widgets that doesn’t have the manual tags. The solution to those is to add more than one dynamic sidebar in wordpress and display them where you want. I like this because I can manage everything from my wordpress admin panel and have everything where I want on the template. Kill two birds with one stone.

I have made a detailed video, which I will recommend you to watch because that will make the steps much more understandable, but I think you need to visit here to actually get the codes because it might not be as clear in the video.

First of all, Open your functions.php which is located in the themes folder.

<?php if ( function_exists('register_sidebars') ) register_sidebar(); ?> [/raw] By default it shows something like I have put above. Replace these codes with the ones below: [raw] <?php if ( function_exists('register_sidebars') ) register_sidebar('2'); register_sidebar('3'); register_sidebar('4'); ?> [/raw] You can add the numbers as you go. Remember you start with 2 because sidebar 1 is already defined. Now is the part where you need to see the video because that explains better with live tutorial. You go to the admin panel, and get to the widgets page, and you will see more than one sidebar there. Upload the widgets in the desired sidebar. Say you want to display the mybloglog recent visitor widget in the footer. You copy that widget in your sidebar 2 or whichever one. Than open the file where you want to display the codes. In our case footer.php [raw] <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(2) ) : else : ?> <?php endif; ?>

Add the codes above, and make sure you change the sidebar number.

This should do it. Enjoy your dynamic sidebar. This will make your life so much comfortable now because you can edit settings through the admin panel rather than editing each plugin file individually.

To stay updated with the blog, please consider subscribing to my full feed RSS. You can also subscribe by Email and have new posts sent directly to your inbox. I hate spam as well, so I promise you that you will not be spammed.

RSS feed | Trackback URI

23 Comments »

Comment by Diane
2008-03-25 23:49:53

Hi Syed, great video but unfortunately no matter what I did I could not see exactly some of the important parts. I even headed over to YouTube to see if it was clearer. The video is larger, but still too blurry for me to see :(

That aside, I’m also wondering does this only work for WP 2.5?


Comment by Syed Balkhi
2008-03-26 02:02:10

sorry about the blur in the video, I guess next time I would just make the fixed size window and fit it all in there. No this will work in any verson if wordpress not just 2.5. I just showed 2.5 because that is the one I have on Balkhis.


 
Comment by Angad Sodhi
2008-06-16 02:18:02

You should really upgrade to WP 2.5
It is much much better!


 
 
Comment by Harry
2008-04-09 18:18:00

Nice one, this worked great your instructions were very helpful, now i can call different sidebars for different pages as i wanted to.
Diane it does work with all Wordpress inc. 2.5. It is not too hard, you can do it in 2 steps.
Step 1. Open functions.php and add the first section of code.
Step 2. Then open up the template page where you want the numbered sidebar to appear, e.g category.php and add the second part of code. Please give more details of what exactly you want for more specific help.

And Syed a problem is you have spaces in your php code between question mark and <.
Again Many Thanks.


Comment by Syed Balkhi
2008-04-09 18:56:23

Thanks Harry, it is fixed now.


 
 
Comment by David Cheong
2008-04-14 13:09:38

At that something new to me, and really straight to the point too. Thanks syed for the guiding video and word guide. :)


Comment by Syed Balkhi
2008-04-14 14:45:32

glad I am able to help you David :)


 
 
Comment by Quest For news
2008-04-14 23:11:07

That was helpful. I figured out how to add the mybloglog widget to a few of my blogs. :)


Comment by Syed Balkhi
2008-04-15 08:00:03

I am glad that I was able to help you a bit. I first used it on Balkhis due to that reason also, but then incorporated it everywhere just to make it more friendly with the admin panel.


 
 
Comment by thorri Subscribed to comments via email
2008-04-17 08:36:32

This was really helpful, thanks!

I added extra sidebars easily. After adding some content, including special php via “Executable PHP widget”, one of my dynamic sidebars includes a corrupt widget that I can’t remove (no “remove” button available - only error message).

Do you know how to “empty” a dynamic sidebar?


Comment by Syed Balkhi
2008-04-17 08:48:29

Umm you can just go to your admin panel. I am assuming that you are on the latest version 2.5

Go to Design > Widgets

On the right hand side it will show Current Widgets and below it there will be a select box saying Sidebar 1, Sidebar 2 and so on. Pick the sidebar where your widget is.

Click to edit your broken widget, and you should see the remove button there.

Hope this helped.


 
 
Comment by thorri Subscribed to comments via email
2008-04-17 10:40:28

Thanks for the reply. I wish it were so straight forward as you say.

The fact is that the top and bottom of the right hand widget is missing — so no “edit” and thus, no “remove”. Only the middle part shows — and in it is only an error message.


 
Comment by thorri Subscribed to comments via email
2008-04-17 10:42:28

Thanks for the reply. I am indeed using WP 2.5.

The fact is that the top and bottom of the right hand widget is missing — so no “edit” and thus, no “remove”. Only the middle part shows — and in it is only an error message.

I can probably just not use “sidebar 3″ which contains the error widget, but just knowing it’s there really annoys me. I wish I could make it go away.


Comment by Syed Balkhi
2008-04-17 11:38:38

edit your functions.php and you can get rid of the entire sidebar all together.


 
 
Comment by thorri Subscribed to comments via email
2008-04-17 17:11:41

I tried editing Sidebar 3 out of functions and then editing it in again. It went away, and came back when I edited it in again.

I think I have a fix though (through WordPress.org’s forums):
http://wordpress.org/support/topic/169863?replies=2


Comment by Syed Balkhi
2008-04-17 18:21:22

I am glad you got your answer.


 
 
Comment by soam
2008-05-31 00:19:46

Im not able to get my functions.php

How to do it??


 
Comment by Angad Sodhi
2008-06-16 02:19:47

Lovely post Syed, I had never heard of such a thing before. Sounds very logical and very useful. But I still like to edit the code itself. My sidebars generally have no widgets at all. I like to put everything in the codes


 
Comment by Rakhshinda
2008-06-18 14:45:47

Thanks for explaining i was trying to do it by myself once and it got real confusing, but i’ll watch this video and learn from it.


 
Comment by Enkay Blog
2008-06-18 17:22:41

Thanks for the great tutorial. I will have to try this out. I was going to ask you, how do you experiment with Wordpress, do you have a test blog set up because thats what I do.


 
 
2008-08-19 00:31:14

Thank you for the tips! It helped me a lot. Now I have two sidebars fully working in my website!!

You should try contribute to Wordpress Codex with this video. I haven’t found a clue on this issue in there.


Comment by Syed Balkhi
2008-08-19 00:58:05

I am glad you liked my tutorial. I made an account on codex and wrote on only one thread. I just can’t find time to go there. I wish I can make my own article saying how to make a dynamic sidebar and sticky it on WP Codecs. If you find people you are welcome to link them to this site.

:)


 
 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.


Hey, I am Syed Balkhi, The guy who is behind Balkhis Inc. I entered the industry back in 2002 not knowing a single thing. I barely spoke english at that time. In the past six years, my language barrier has been eliminated. Aside from English, now I also speak html, and php. Along with the languages I have also managed to master a few arts. Art of web-designing started when I first entered. Messing around with photoshop, I learned how to create my first web design. Now I founded a web designing firm Uzzz Productions. After running numerous amount of websites in various niche, I have mastered the art of web-development. Now I am compiling a resource of what I already know, and what I am learning on this blog. This resource is to help me if I ever need a guide to look back to, and it is help my fellow webmasters.

Read more about Syed Balkhi