One of the most annoying experiences on the Web today is being delivered the wrong ad at the wrong time. It doesn’t ruin my experience, but I’m always shaking my head, wondering why the programmers didn’t do a better job.
I was thinking about that during some redesign around here, then decided to solve a problem: deliver my Thesis affiliate image ads only to people that were reading posts related to the Thesis framework. Personally, I don’t like my site cluttered with ads, but at the right time, in the right place, to the right person, I want the flexibility of including an advertisement.
There are probably many other ways to do this, so if you have something interesting to share, please write a comment below. Now I’m going to show you how I did it.
First, you’ll need to have all your Thesis posts slapped with the same tag. You could do the same thing with categories, but I didn’t. I use the tag “thesis”. That’s how I target the right audience.
We’re going to drop some code into either the custom_functions.php file, or using the time saving plugin Thesis OpenHook, at thesis_hook_after_post
. I’ll show you how to do this with OpenHook, but using the custom_functions.php file can be done too, with a little more effort.
Using Thesis OpenHook, look for thesis_hook_after_post
and drop the following code in there:
<?php if (has_tag('thesis')) { ?>
<p style="text-align: center;">
<a href="http://www.shareasale.com/r.cfm?b=202503&u=520806&m=24570&urllink=&afftrack=">
<img src="http://www.shareasale.com/image/24570/468x60.png" alt="Thesis Theme for WordPress: Options Galore and a Helpful Support Community" border="0" />
</a></p>
<?php } ?>
See that first WordPress conditional tag there, has_tag('thesis')
— well, some people might have tried using the more common, is_tag()
, but they would have been wrong. The difference between the two conditions is that one looks for a binary condition — yes or no — while the other, has_tag
is looking for a positive result among many possibilities. Trust me, this is the way you want to do it.
After the beginning — <?php if (has_tag('thesis')) { ?>
— you can drop in your affiliate code, what ever it may be. Of course, this method doesn’t only work with Thesis affiliate links. You could use Amazon code in their for book reviews, for example. I’m sure you can think of many other applications.
And you don’t have to put the affiliate code at the end of a post. Using Thesis hooks you can drop it many other places, at the right time, for the right person.
Do you have any other suggestions on how to target ads using Thesis? Drop a comment below.
Photograph by Hans Splinter and republished here under a Creative Commons license.