Splitting the Sidebar in a 3 Column WordPress Theme
I set my kids up with their own blog for the summer to help encourage them to keep their writing skills sharp (since all previous motivational attempts failed). For their new site I selected the WordPress theme Pride created by Small Potato and available for download at WpDesigner.com.
I thought the theme was fantastic! My kids, however, thought otherwise. They wanted a different color scheme, which I managed to pull off with my limited Photoshop skills. They also, however, didn’t like the double sidebars on the right side of the page. They wanted me to split the sidebars and flank both sides of the main content with a single sidebar. I said no problem, and here’s how I did it.
Note: In order to follow along with my explanation, I suggest you download the Pride theme from WpDesigner.com and open the various php files in a text editor.
Start With the Original Pride Theme
The original theme contains both sidebars in a single sidebar.php theme file; however, notice how both of these sidebars are off to the right side of the page:
If you examine the contents of the sidebar.php file, you can see where the first sidebar begins and ends, and where the second sidebar follows. The sidebar gets inserted into the index.php, page.php, single.php, archive.php, and search.php files after the closing tag of the main class:
< /div><!-- end main column -->
< ? php get_sidebar(); ?>
NOTE: In order to avoid strange behavior, I inserted into this post all example PHP code formatted incorrectly.
Move the Sidebars to the Other Side
The sidebar formatting in the style.css file has the sidebar set to “float left.” Since the sidebars are inserted after the “main” section, their float setting causes them to push flush to the margin settings of the “main” section. In order to split the sidebar I moved the get_sidebar PHP call from its original location to before the “main” section:
< ? php get_sidebar(); ?>
< div class ="main">
When I checked the results, the sidebars were now on the left side of the page but still together. Now I needed to split them apart.
Duplicate the Sidebar Format Settings and Split the Sidebars
There are 15 format settings specifically named “.sidebar” in the style.css file. I copied all of these settings and pasted them a second time into the style.css file. Then, on the newly inserted batch of format settings, I renamed them all to “.sidebarright”. Then, in order to avoid future confusion, I renamed all of the original “.sidebar” format settings to “.sidebarleft” and saved my changes.
I left the top level format setting for “.sidebarleft” unchanged:
.sidebarleft{ float: left; width: 200px; margin: 0 0 0 20px; display: inline;}
In the “.sidebarright” top level format setting, however, I changed the float setting from left to right:
.sidebarright{ float: right; width: 200px; margin: 0 0 0 20px; display: inline;}
Next, I edited the sidebar.php file and inserted these new classes where “sidebar” was originally called. For the first sidebar class setting, I made the following change:
< div class=”sidebarleft”>
Then, in the second sidebar section I changed the class name to the following new class:
<div class=”sidebarright”>
I saved my settings and previewed my changes. The sidebars were split, but my margins weren’t exactly the way I wanted:
Update the Margin Formatting to Get the Correct Spacing
The left sidebar has 20px in the left margin which was the original format setting. The right sidebar looked fine because the 20px left margin works correctly on the right side of the page. To correct the problem I only needed to change the margin settings for the “.sidebarleft” top level format setting and give it a 20px right margin:
.sidebarleft{ float: left; width: 200px; margin: 0 20px 0 0; display: inline;}
I saved my changes and reloaded the page, and like magic the sidebars flanked the left and right sides of the main page content with proper spacing.
Sidebar Comments Caused Problems with Internet Explorer
When I originally did the sidebar split work, I had comments all over the place in the sidebar.php file. I wanted to keep track of what everything was in the sidebar so future edits would be easy. With FireFox these comments caused no problem whatsoever; however, with Microsoft Internet Explorer version 6.x, the comments caused strange background colors in the sidebar:
After much frustration I gave in and removed the comments which resolved the problem.
Moral of the story — Sidebar splitting is easy and more about CSS settings than specialized WordPress function calls and template tags. And, always test your design changes with as many browsers as possible, and watch out for comments in your PHP files, Internet Explorer doesn’t seem to like them.
Share, Bookmark, or Email this post
|
|
If you liked this post, subscribe to TechTraction's RSS feed or TechTraction's email feed
Filed under: How-To & Tech Tips

Maybe it’s just me, but I think it would be so cool to be able to ask my kid(s) one day how their blogs are doing. … I suppose I could just check it out myself, but then we’d have nothing to talk about! Seriously though, this must be kinda cool for you. (#):)
Yeah, it has been lots of fun working with my kids on their blog. They think it’s “the bomb”, and I’m having a blast.
I must admit, however, that when I mention that my kids have a blog to most people, they immediately think “MySpace” and then I get those “looks” of “are you crazy letting your kids out their on the …..Internet?!” People that don’t do much on the computer get all of their information from sensational news headlines. They don’t understand that my kids operate under aliases, they don’t put any personal information out there, and that I have to approve all posts and comments. In my opinion it’s all very safe. Besides they’re learning a alot and having fun doing it.
Anyway, thanks for the comment.
I think you bring up some good points. Furthermore, I think the more knowledgeable YOU are and the more plugged in to THEIR online lives you are, the better off they’ll be anyway. *nod*
I have added you to my linkback post, started to JonCow ~http://homebizblogger.com/2007/07/20/the-link-back-list-post-and-comment-to-be-added/
Great! Thanks eve. I’ll follow up this weekend and help with the movement.
Hey Bret, thanks for trying to convince your kids with Pride :). I thin you would have had an easier time if you used mutliple classes per div. For example: class=”sidebar left”
Hi Small Potato, thanks for stopping by and leaving a comment. As for the multiple class idea…didn’t I sort of do that with my sidebarleft and sidebarright classes? Did I miss something or is there another way to do it?
Thanks
This is why i love the internet so much, i mean there will be information about something very specific on the net. I was just looking for some help when i saw this post. Three cheers to the net and you!
The thing is i still dont get the point, i can get my side bar to obey me.I think my theme is one of the worst ones that wordpress has produced!
Aroah, the point of the post was to describe the steps required to take a 2 sidebar theme where the sidebars were both floated to the right and split them so one is on the left and the other is on the right with the main content in the middle. If you are having difficulty with your current theme, you might want to try another one. I’d suggest looking for a very simple theme, that way you have less to dig through to find what needs to be changed. Hope that helps. If not, please comment with some further details and I’ll do what I can to help. Thanks for the comment.
“(since all previous motivational attempts failed).”
I did laugh at this, mine are the same but good to hear you are thinking outside the box! Mine are all very keen on having websites so starting with some basic blog setups is a quick an easy way to get them something up and live.