Adding additional page with own sidebar to WordPress Template
Posted by Roland | Posted in Tutorials | Posted on 29-11-2009
Tags: page, sidebar, template, wordpress
6
Howdy, People from all over the world
How are you? Hope everything is fine, you’re having a lot of clients while doing freelance or doing best of you if you work in a design company
Sorry I haven’t visiting you for a while and there were no posts from me. Meanwhile I was out, Dmitri posted Well, I was visiting RL Creative in case of comments, but had no time to write. A loooot of work and studies. Exam are coming so I have to study better.
This week I had a lot of work with WordPress powered website at work. I had to do some things I haven’t done before
Well, I’m kind of person, that always likes to do something thatВ hasn’tВ done before…
This time I had to deal with the problem of showing various content in sidebars of various pages. Well, I know there is a possibility to add several sidebars and then choose them by defining sidebar name in sidebar variable. But, it worked only with pages for me. Maybe I made some mistake somewhere. So, I decided to create a new page design with it’s own sidebar and add it to wordpress.
I know, that lots of you know how to do that. Well, if you do know, you can just leave a comment telling about how you do that. For those, who never did that and thinks that it might be useful, here is how it is done.
All the templates are different. Sometimes we have a template that is already various sidebars. Sometimes our template uses one sidebar and that’s all. Depending on that there are various things you will have to modify.
If your template is using various sidebars
First thing you have to do is to create a copy of existing page design and name it how you want. I named it page_calendar.php. Upload it in the same folder, where your page.php file is. I bet it’s wp-content/themes/theme-name folder. So, after uploading it will show up in your Appearance — Editor menu.
We now will make a small modifications in your new page to add a new sidebar to it.
First of all, add this text to the top of the file:
1 2 3 4 5 | <?php /* Template Name: Page name */ ?> |
So, now your page has a name (write your own name instead of “Page name”) that will display also in the list of theme files in Appearance — Editor. Don’t click Update. We’re not finished here.
Just find the next line in your page design:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Sidebar_2") ) : ?>
This Sidebar_2 is the same that will be shown on your Widgets page. I never think of something hard and create a simple names I could easily remember. This time it’s just Sidebar_2. You should definitely use your own so it would be easier for you to remember ![]()
Now you can click Update.
Next file we will have to modify is Theme Functions file – functions.php.
open it and search for next code (it may not be 100% as it is shown below, so don’t search for the whole code. Search for the string function_exists(‘register_sidebar’)):
1 2 3 4 5 6 7 8 9 | if ( function_exists('register_sidebar') ) { register_sidebar(array( 'name' => 'Sidebar_2', 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', )); } |
You may probably already have some sidebars defined here. To be sure everything will work — copy your block of if function and paste somewhere after the first block you’ve just copied. So, every if block defines a sidebar. And making as many if blocks as you want will make as many sidebars as you need ![]()
So, now let’s look at this code. On Line 3 you have to define the name of the sidebar. REMEMBER — this should be the same that you’ve already defined in your new Page file. It should be exactly the same.
I removed the html code from ‘before_widget’, ‘after_widget’…and so on, so you won’t be mislead. Don’t do that to your own code. It should be exactly as on other sidebars, except the name
So, that’s all. You can now go to your widgets page and put widgets into new sidebar.
If your template had only one sidebar.
The process is almost the same as on previous except one thing. You don’t find this dynamic_sidebar line in your page.php file:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Sidebar_2") ) : ?>
It will be just the static sidebar:
<?php get_sidebar(); ?>
So, now you will just need to replace the static sidebar with dynamic one from above and define a name as I’ve shown above. And that’s it ![]()
Small modifications but big possibilities. The first time I did that, it took me about 30 minutes to understand what and where should be defined. Concerning the fact that I didn’t find any good articles that would describe the whole process I made that quite quickly. Today I made some modifications on another blog and I added a new page with it’s own sidebar in 2 minutes
So, enjoy
And I’ll be back soon
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.


Great tutorial! thank you!
.-= WPSMASH.COMВґs last blog ..55+ Free Premium WordPress Themes =-.
Like or Dislike:
0
0
This is a great tutorial Roland — I am quite new to the WP platform , but as soon as I acquaint myself a bit further, I would love to try more things on it , as I love playing around with code
. I have def bookmarked your site for further “Knowledge” . Thank you again for making this comprehensible ( even for a newbie WP blogger like myself )
Best wishes for the Holiday season & all the very best for 2010 ! [ Good luck w/ your exams ! ]
M.пЈї
.-= MiaВґs last blog ..Enabling Your “FF” Browser at Warp Speed =-.
Like or Dislike:
0
0
P.S : Roland , you may want to fix your Retweet Button to point to your twitter user-name e.g :RT @rl_creative ; and not at RT @tweetmeme as it presently stands ( since all your RT are not being directed to you ) . Just edit your plugin settings of your Retweet Button and set your name . But Im sure you will know what to do
Good luck !
M.пЈї
.-= MiaВґs last blog ..Enabling Your “FF” Browser at Warp Speed =-.
Like or Dislike:
0
0
Hey, I found your blog in a new directory of blogs. I dont know how your blog came up, must have been a typo, anyway cool blog, I bookmarked you.
Like or Dislike:
0
0
I do not think I’ve seen this described that way before. You actually have cleared this up for me. Thanks!
Like or Dislike:
0
0
web design is also a good hobby and a great job too. web design jobs pays very well.;.
Like or Dislike:
0
0