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.
Didn’t work very well on my site, the side bar ended up on the bottom and i think there were some CSS problem.
everythinghosting.org recently posted..Netfirms Review
Try adding it above footer.php in single.php file It should work
This is a great fix. Thanks a bunch. When using it, though, pages are impacted as well as posts. How do I get pages to stay full width and posts to have a sidebar?
Chris recently posted..Get your own #Anywhere5K gear. Run your own #Anywhere5K race.
Remove the || is_page() part and it will only show on posts
Thanks @Zeaks!
Chris recently posted..Get your own #Anywhere5K gear. Run your own #Anywhere5K race.
One more thing. The previous and next links are goofed. It’s most likely something I did wrong with CSS. Can you have a look? BTW, I moved them to the bottom. http://anywhere5k.com/2012/03/zombies-apocalypse-5k-sweet/
Chris recently posted..Do as the Mayans do
They look fine in firefox, but in the next version I put them back how they originally were in NomNom. try using
#nav-single { width: 100%; }Seriously dude, you rock the house! That worked perfectly in all browsers. Thanks!
Hi Zeaks,
Did you see my message on Facebook to you? I sent the two zips of the twenty-eleven theme and the child theme. You’ll recognize my name as Bern Raftery.
BLR recently posted..An Effective Business Card (Part 2)
BLR on April 26, 12 at 9:06 pm said:
Zeke, your information is wonderful. I just can’t figure out what I did wrong. My comment #respond, for my blog isn’t working at all. I still get an error.
http://www.avsoffice.com/what-does-sba-gov-have-to-say/#respond
I also continue to get the error message: 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); }
Can you tell me what I did wrong?
Best regards, and thank you in advance,
BLR recently posted..What Does SBA.gov Have To Say?
Where did you add the code? If there’s an issue, it should be throwing an error message, it’s displaying the php code though.
Thank you for getting back to me.
I tried several different ways to add the functions.php code in the CHILD theme.
a) added to the bottom.
b) put at beginning.
c) overwrote the other code in there.
My pages are fine, it is the posts that are giving me this code. Step 1 at least made some improvement. Which added the sidebar contents, whereas before it was only the error message.
Thank you again!
BLR recently posted..What Does SBA.gov Have To Say?
Did you include the opening php tag in the functions file? If not add
at the very top.
Hi Zeke,
I went in to the functions.php, and confirmed that <?php is definately there at the beginning, I copied and pasted the entire code provided in the step. Thank you for asking, though.
BLR recently posted..What Does SBA.gov Have To Say?
@Blr http://www.avsoffice.com/what-does-sba-gov-have-to-say/ is missing it’s style, I can’t even view the source of your website to see what theme you’re using. (I know it’s twenty eleven or a child theme)
If you could zip your theme and email it to me, or post it to me as an attachment in a message on the forums I’ll have a look. It isn’t a question of if the code works, it cannot with because it’s not being executed.
Was this theme installed by your webhost or did you download it from WordPress.org? Sometimes webhosts add their own code to scripts they offer which could be causing issues with this code. This is the same code I use on this site and in NomNom theme.
Sure Zeaks, I’m very grateful for your follow through.
I don’t see a way to add attachments here. I’ll put it through to the sites Facebook page via a message. Would that work for you?
BLR recently posted..What Does SBA.gov Have To Say?
Your functons file looks fine, your single.php is missing it’s code, the function does not get added to single.php only the sidebar call as it says. Copy single.php from Twenty Eleven, and add the sidebar call to it. This is why that page is not displaying anything properly.
Oh Zeaks! I owe you a GREAT BIG virtual hug! Thank you!
Just one more question, I create child themes for everything. Why would WordPress overwrite those if they are in a child theme folders. I suspect it may be because the opening has to read: /* The Child Template for … */ or reference somewhere in the opening a Child Theme, but I am not positive.
Respectfully submitted,
BLR recently posted..An Effective Business Card (Part 2)
WordPress won’t overwite them, the template tags don’t matter. As long as the child theme is in it’s own folder and not named the same as the default themes.
Thanks, any idea how this can happen then? A couple of times, after I ran an update from WordPress and themes a couple of folks’ websites, I have lost footer information, referencing my services. I usually add a small business graphic and I add it, in addition to the “Proudly Powered by WordPress… and theme info.” Once I rememove the W.P. & Theme info all together, but still, the W.P. & Theme info come back, and my info gets deleted. It’s very frustrating. All child info is in their own folder. It’s bizzarre.
Start a thread on the forums and post the code your using, also mention what files you’re adding it to. When upgrading wordpress the only themes it comes with are Twenty Eleven and Twenty Ten, so there’s nothing that is able to overwrite what is in your child theme.
The only thing I can think of is you’re upgrading it from your webhost, instead of the upgrade option in WordPress admin, then it may remove the current install and reinstall it. I seem to remember your site being some sort of WordPress install host, I couldn’t even view the source of your page, so this might be the issue.