Use Conditional Tags to Empower Your Content
Oct 8th, 07 | 2 remarksHave you ever wanted to display different content for certain pages on your blog? Why not right? Contextually relevant links, ads, or content is always a good idea. Until recently, I had been creating separate sidebar templates to accomplish this, but it’s the hard way ’round.
When I began coding Pink Adaptations, I discovered conditional tags and the power and flexibility they afford. If you’re not familiar, conditional tags are essentially a way to show content based on whether a specific requirement is met.
It’s done by using an if statement (not unlike The Loop). You may have seen this bit of code if you’ve ever looked through the default theme packaged with Wordpress:
<?php /* If this is a category archive */ } { ?>
<p >You are currently browsing the archives for the
<? php single_cat_title(''); ? > category.</p >
? php } ? >
I stupidly ignored this for a long time because I didn’t fully understand its purpose, but this one snippet can be tweaked to display predetermined content not just for the archive page, but also your index, single post, search, Pages, and even custom templates.
For example, on my Themes page, I wanted to show a sidebar blurb about custom theming, a donation option, etc. I didn’t want this info on every page across my site, so I added the following conditional tag in sidebar.php:
< ?php if (is_page('wordpress-themes')) { ? >
< p>Blah blah blah.</ p>
< ?php } ? >
This refers to the slug of my Themes page, and when the condition is met it displays only the content I specified.
Conditional tags are a very efficient method of controlling various sidebar content for different pages - and how nice to be able to manage all of it from one place! Not to mention the fact that your pages will load faster, since only one file is being called site-wide. :)
p.s. If you copy/paste the snippets above don’t forget to remove the spaces.

Look at you! Gettin’ all fancy with the php code! :) Thanks for this tip - I’ll bookmark it as I’m sure I’ll need it sometime soon.
Oct 8, 07 | 10:40 amLOL I must be on a roll! :)
Once I figured out the best way to set up the if statements, this method saved me a lot of time in building out the theme(and making changes afterward). I think you’ll love it Randa, and if you need a hand with it just give me a shout!
Oct 8, 07 | 12:37 pm