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 728x90px 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










This article has 5 Comments
how did you make it float right like that?
the sidebar
or what ?
how do i set up my own banner image like on http://www.rockitpro.com ?
Thank you for this information.
Pings:
Leave a Reply