By default Twenty Eleven doesn’t display a sidebar on the post view page, but this can be added fairly easy.
TricksMommy.com describes how this can be done by editing CSS.
I ran into a few issues doing it this way. Using this method when the single column layout is selected, pushes the content to the left without a sidebar showing, it also causes issues with the edit post link and the author Bio if active, there may be other areas not displaying right. These can easily be fixed by adjusting the css.
That might not effect most users, but since I usually allow downloads of child themes I make I needed a better way.
The method I used curtsey of TransformationPowertools.com worked best with very few issues. (slight css edit for next/previous links and resize author bio)
Start off by creating a child theme, this is always the best way to go I don’t care who says it isn’t.
Open single.php and near the bottom add
<?php get_sidebar(); ?>
right above
<?php get_footer(); ?>
Now create a functions.php file for your theme and add this to it
<?php
add_filter('body_class', 'blacklist_body_class', 20, 2);
function blacklist_body_class($wp_classes, $extra_classes) {
if( is_single() || is_page() ) :
// List of the classes to remove from the WP generated classes
$blacklist = array('singular');
// Filter the body classes
foreach( $blacklist as $val ) {
if (!in_array($val, $wp_classes)) : continue;
else:
foreach($wp_classes as $key => $value) {
if ($value == $val) unset($wp_classes[$key]);
}
endif;
}
endif; // Add the extra classes back untouched
return array_merge($wp_classes, (array) $extra_classes);
}
Here are a few css adjustments I added, the nav next/previous one is really all that’s needed though.
.nav-previous {
float: left !important;
}
#respond {
margin: 0 auto 1.625em;
padding: 1.625em;
position: relative;
width: 88.9%;
}
.commentlist {
width: 78.9%;
}
/* adjust author bio */
.singular #author-info {
margin: 2.2em 0 0;
padding: 20px 5.4%;
width: 550px;
}
Now your site should display a sidebar properly using any layout.
Thanks, i have tried it on my twenty eleven and it works. But i have tested that if i did not change the CSS, it seems everything was fine.
However i noticed that the comment area is squeezed a little bit.
Xrvel recently posted..Sphinx Search Engine for vBulletin 4
With the bit of CSS I added it should increase the width of the comments slightly. The author BIO “should” display too wide (most people don’t use that feature though)
Glad it worked for you
Zeaks recently posted..Easily add Wp-PageNavi to Twenty Eleven
Thank you, save me a lot of time for these!
sanjay recently posted..How to create your own Opt-in Form in Photoshop
Many thanks for sharing this, worked perfectly. Cheers!
mark recently posted..Prohibition Peach Schnapps
Your tutorial is the only one that’s actually worked for me. Sigh. However, my real goal was to put two sidebars with the content between in my posts, but the other tutorials I’ve found online have not worked. Is that layout for the post pages just a lost cause?
Darleene recently posted..Awesome ceiling decorations
Hi Darleene, I’m unsure what you’re trying to do. Do you want a 3 column layout? Or just a 3 column layout on the single post page?
A 3 column layout for just the single post pages.
Darleene recently posted..Awesome ceiling decorations
I was reading your post on wordpress.org, the suggestion given http://wordpress.org/support/topic/twenty-elevel-3-column?replies=18#post-2486487 was right.
In my NomNom theme I added an extra sidebar. It can still be used for 2 column layouts, but it’s displayed directly under the default sidebar, so it looks like one in all layouts except for 3 column.
If you were to use a conditional as webmystery mentioned for single post pages, you could use the 3 column layout instead.
Using the tutorial on voodoopress which you mentioned, would probably do what you needed as well. I remember reading that while I was creating the 3 column layouts for my theme.
If you can’t get it working, let me know on my forums and I’ll try and help.
I hate leaving my site like this, but I wanted you to see what happened. So I followed Voodoo’s tutorial *again* and got all sorts of funkiness. But at least the content has been moved to the center!
http://www.weddingdecoratorblog.com/2011/12/awesome-ceiling-decorations/
Darleene recently posted..Awesome ceiling decorations
Nuts, sorry! I’ll post this in your forums.
Replied to your post
Thanks for posting this! I’ve been messing around with this for a few hours now. The only problem is that it also aligned my single pages to the left. Do you know how I could keep that from happening? My single pages have no sidebar and I would like to have them still be center aligned.
Thanks,
Botzi
Hi Botzi. Thanks for pointing this issue out. The reason it’s doing this is because I’ve added is_paged to the function. I did this to also include the media pages, guess I’ll have to find a different way to include them.
Anyways, just remove || is_paged() from the function you added to functions.php so it looks like this
<?php add_filter('body_class', 'blacklist_body_class', 20, 2); function blacklist_body_class($wp_classes, $extra_classes) { if( is_single() ) : // List of the classes to remove from the WP generated classes $blacklist = array('singular'); // Filter the body classes foreach( $blacklist as $val ) { if (!in_array($val, $wp_classes)) : continue; else: foreach($wp_classes as $key => $value) { if ($value == $val) unset($wp_classes[$key]); } endif; } endif; // Add the extra classes back untouched return array_merge($wp_classes, (array) $extra_classes); }Thanks quick reply Zeak! That worked!
btw, awesome site, reading through some of your other tuts.
Best,
Botzi
Hi,
You say : “Now create a functions.php file for your theme and add this to it”
but I stil have a functions.php file !?! What should I do ?
- Create another functions.php file ? If yes where to put it ?
- Add the php code (you give) in the existing functions.php ? If yes, where exactly ?
Thanks in advance.
Ludovic
Ludovic recently posted..Implantez vous sur le marché de la perte de poids, et gagnez des milliers d’euros en recommandant le produit d’affiliation Fourneau Bruleur de Graisse…
If you already have a functions.php then add the code after your current code. It’s assumed you are using a child theme when following this tutorial.
If you get errors, I’ll need to take a look at your functions.php file, you’ll have to post it on the forums, or send me a private message on the forums.