Featured Post

Essentials of Macro Photography

My name is Dmitri Gomon, I am a friend of Roland and also a new author of RL Cre­ative blog. My main hobby and pas­sion is pho­tog­ra­phy, more pre­cisely nature and macro pho­tog­ra­phy. Today I decided to write about lat­ter, since I have been work­ing mostly in style of macro-photography. Peo­ple...

Read More

Adding additional page with own sidebar to WordPress Template

Posted by Roland | Posted in Tutorials | Posted on 29-11-2009

Tags: , , ,

6

main copyHowdy, Peo­ple from all over the world :)

How are you? Hope every­thing is fine, you’re hav­ing a lot of clients while doing free­lance or doing best of you if you work in a design com­pany :)

Sorry I haven’t vis­it­ing you for a while and there were no posts from me. Mean­while I was out, Dmitri posted Well, I was vis­it­ing RL Cre­ative in case of com­ments, but had no time to write. A loooot of work and stud­ies. Exam are com­ing so I have to study better.

This week I had a lot of work with Word­Press pow­ered web­site at work. I had to do some things I haven’t done before :) Well, I’m kind of per­son, that always likes to do some­thing thatВ hasn’tВ done before…

This time I had to deal with the prob­lem of show­ing var­i­ous con­tent in side­bars of var­i­ous pages. Well, I know there is a pos­si­bil­ity to add sev­eral side­bars and then choose them by defin­ing side­bar name in side­bar vari­able. But, it worked only with pages for me. Maybe I made some mis­take some­where. So, I decided to cre­ate a new page design with it’s own side­bar 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 com­ment telling about how you do that. For those, who never did that and thinks that it might be use­ful, here is how it is done.

All the tem­plates are dif­fer­ent. Some­times we have a tem­plate that is already var­i­ous side­bars. Some­times our tem­plate uses one side­bar and that’s all. Depend­ing on that there are var­i­ous things you will have to modify.

If your tem­plate is using var­i­ous sidebars

First thing you have to do is to cre­ate a copy of exist­ing 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 upload­ing it will show up in your Appear­ance — Edi­tor menu.

We now will make a small mod­i­fi­ca­tions in your new page to add a new side­bar 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 dis­play also in the list of theme files in Appear­ance — Edi­tor. Don’t click Update. We’re not fin­ished 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 Wid­gets page. I never think of some­thing hard and cre­ate a sim­ple names I could eas­ily remem­ber. This time it’s just Sidebar_2. You should def­i­nitely use your own so it would be eas­ier for you to remem­ber :)
Now you can click Update.

Next file we will have to mod­ify is Theme Func­tions 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' =&gt; 'Sidebar_2',
 'before_widget' => '',
 'after_widget' => '',
 'before_title' => '',
 'after_title' => '',
    ));
}

You may prob­a­bly already have some side­bars defined here. To be sure every­thing will work — copy your block of if func­tion and paste some­where after the first block you’ve just copied. So, every if block defines a side­bar. And mak­ing as many if blocks as you want will make as many side­bars as you need :)
So, now let’s look at this code. On Line 3 you have to define the name of the side­bar. 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 mis­lead. Don’t do that to your own code. It should be exactly as on other side­bars, except the name :) So, that’s all. You can now go to your wid­gets page and put wid­gets into new sidebar.

If your tem­plate had only one side­bar.
The process is almost the same as on pre­vi­ous 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 sta­tic sidebar:

<?php get_sidebar(); ?>

So, now you will just need to replace the sta­tic side­bar with dynamic one from above and define a name as I’ve shown above. And that’s it :)
Small mod­i­fi­ca­tions but big pos­si­bil­i­ties. The first time I did that, it took me about 30 min­utes to under­stand what and where should be defined. Con­cern­ing the fact that I didn’t find any good arti­cles that would describe the whole process I made that quite quickly. Today I made some mod­i­fi­ca­tions on another blog and I added a new page with it’s own side­bar in 2 min­utes :) So, enjoy ;)

And I’ll be back soon ;)

No related posts.

Related posts brought to you by Yet Another Related Posts Plu­gin.

Comments (6)

Great tuto­r­ial! thank you!
.-= WPSMASH.COMВґs last blog ..55+ Free Pre­mium Word­Press Themes =-.

Like or Dis­like: Thumb up 0 Thumb down 0

This is a great tuto­r­ial Roland — I am quite new to the WP plat­form , but as soon as I acquaint myself a bit fur­ther, I would love to try more things on it , as I love play­ing around with code :D . I have def book­marked your site for fur­ther “Knowl­edge” . Thank you again for mak­ing this com­pre­hen­si­ble ( even for a new­bie WP blog­ger like myself ) :D

Best wishes for the Hol­i­day sea­son & 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 Dis­like: Thumb up 0 Thumb down 0

P.S : Roland , you may want to fix your Retweet But­ton to point to your twit­ter 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 plu­gin set­tings of your Retweet But­ton and set your name . But Im sure you will know what to do :D Good luck ! :)

M.пЈї
.-= MiaВґs last blog ..Enabling Your “FF” Browser at Warp Speed =-.

Like or Dis­like: Thumb up 0 Thumb down 0

Hey, I found your blog in a new direc­tory of blogs. I dont know how your blog came up, must have been a typo, any­way cool blog, I book­marked you. :)

Like or Dis­like: Thumb up 0 Thumb down 0

I do not think I’ve seen this described that way before. You actu­ally have cleared this up for me. Thanks!

Like or Dis­like: Thumb up 0 Thumb down 0

web design is also a good hobby and a great job too. web design jobs pays very well.;.

Like or Dis­like: Thumb up 0 Thumb down 0