If Conditional tags for Wordpress themes
One year ago, I had some ”problems” with a wordpress theme because I wanted a simple thingy and I didn’t know how to do it: make certain stuff (ads, categories, widgets) to appear or disappear depending on the type of page I wanted to add them. This trick is good for placing, rotating ads especially in the header, sidebar and footer, based on conditional tags that are built in wordpress.
The first conditional tag that describes your index or home page is: is_home(). I will write you an example shortly but now I let me explain why you should use this. Let’s say you have an ad spot of 728×90px in your header or footer and in that spot you want a certain banner to appear when you are browsing the index page and another banner when you are reading a post or viewing a category page. For this you can place the following php cod in that spot:
if (is_home()) { echo '<img src="bannerad.jpg"/>'; }
That was for the index, now for a single post the code looks like this and for a page you just change is_single() with is_page()
if (is_single()) { echo '<img src="bannerad.jpg"/>'; }
So the wordpress conditional tags are very easy to use and handy, a bigger list of tags you can see and learn here at codex wordpress! This is just a simple introduction and I hope it helps you









3 Responses to “If Conditional tags for Wordpress themes”
kev
January 5th, 2008 at 6:31 pm |
how did you make it float right like that?
admin
January 5th, 2008 at 8:48 pm |
the sidebar
or what ?
WordPress Conditional Tags - Posted In WordPress | Bayu Albelly - .SlackbloG Journal
May 15th, 2008 at 3:27 am |
[...] If Conditional Tags For WordPress Themes [...]
Leave a reply