Customized sidebar on single posts and pages
written on May 13, 2008 in Tutorials
I was playing around with the Similar Posts WordPress plugin and I wanted to have it show on the sidebar when it was a single post or page. Now I’ve done something similar before, but it was only to display text:
if (is_single()){
echo "This Entry This is the permanent link for the entry ";
echo the_title();
echo "This post has been filed to ";
UTW_ShowTagsForCurrentPost("commalist");
echo ".";
echo "Related entries:";
UTW_ShowRelatedPostsForCurrentPost("posthtmllist");
echo "
";
}
But the thing was, I had no idea how to do this when I wanted a php code to show up when it was a single post. i knew I’d have to use the is_single() WordPress conditional tag, but I didn’t know how to implement that with the similar post code:
After playing around with various combinations, this is my working result:
<?php if (is_single()): ?>
<?php similar_posts(); ?>
<? php endif; ?>
Of course, you can replace the is_single() with any other WordPress conditional tags and replace the <? php similar_posts(); ?> with another php snippet. Just make sure you always add the <? php endif; ?> at the end.
I’m really no expert in php, but this solution worked for me, so if anyone has a better method of getting a php snippet to show up in single WordPress posts, please share with me! Thanks!Error processing request


Comment?