Dynamic sidebars for single posts and pages

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

You might like these posts:

Excluding posts from feeds
Removing ads for your readers
Transparent background and opaque text
Add an archive for your Q*Bee trade log
Bloggers: Pinterest is your friend

Subscribe

Did you enjoy the post? Why not subscribe today?
rss feed Subscribe via RSS
rss feed Subscribe via Email
Follow Super Girl Subscribe via Bloglovin

Or subscribe exclusively to my tutorials:
rss feed Tutorials via RSS
rss feed Tutorials via Email

More Tutorials

Recent Photos

Fendi sunglasseslazy afternoonWhat's this?in deep thoughtHuh?Chilling with her daddy

The Leftovers