Deliver targeted ads to visitors using WordPress

This is the Targeted Ads Approach

Wouldn’t it be great if you could plop a targeted message in front of visitors eyes, and increase conversions??

SEE HOW EASY IT IS TO DELIVER TARGETED ADS!

Do you have a site with a broad central topic, and lots of sub-categories, where you display ads? Sometimes you wish you could deliver an ad based on the category, tag, or even the sidebar. It’s pretty easy to do, and in this scenario it involved a bit of HTML and some PHP conditional statements.

First, the PHP. Let’s begin by displaying an ad on a post by categories.

<?php if (is_category('Copywriting Basics')) { ?>
Replace this text with the html to display the product for Copywriting Basics
<?php } elseif (is_category('Copywriting Creativity')) { ?>
Replace this text with the html to display the product for Copywriting Creativity
<?php } elseif (is_category('Copywriting Freelancing')) { ?>
Replace this text with the html to display the product for Copywriting Freelancing
<?php } else { ?>
Place the html code for the product you want to display on all other categories. Leave this blank to display nothing on all other categories.
<?php } ?>

In the “Replace the html…” sections, we will do just that. Let’s put together some code to do that.

Sample HTML:

<div style="width:590px; height:180px; background:#fef7cd; padding:5px; margin:0 0 10px 0; border-top:1px solid #efe9b0; border-bottom:1px solid #efe9b0;">
 <img src="http://www.freelancecopywritingblog.com/wp-content/themes/premiumnews/images/hotcopyfast.gif" width="116" height="168" hspace="20" align="left"> 
 <h2 style="font-size:22px; line-height:24px; color:#CC3300; letter-spacing:-1px; margin-bottom:5px;">This is the Targeted Ads Approach</h2>
 <p style="line-height:1.4em; color:#000000; font-size:16px; font-family: Trebucher MS, Verdana, Arial, Helvetica, sans-serif; margin-bottom:5px;">Wouldn't it be great if you could plop a targeted message in front of visitors eyes, and increase conversions??</p>
 
<p align="center" style="line-height:1.4em; color:#000000; font-size:16px; font-family: Verdana, Arial, Helvetica, sans-serif; margin-top:15px; font-weight:bold;text-decoration:underline;"><a href="youraffiliatelinkgoeshere" style="color:#000; font-weight:bold; text-transform:upppercase;">SEE HOW EASY IT IS TO DELIVER TARGETED ADS!</a></p>
</div>

Of course, I’d recommend flushing that inline CSS out and attaching it to a div class, but you get the idea. You can change up the wording, affiliate link, and image for each snippet you insert.

But wait, there’s more. Here’s an example of how to do the same things, only using your sidebar:

 
<? php if (is_home()  ) { ?> 
<?php include (TEMPLATEPATH . '/sidebar.php'); ?> 
<?php } elseif ( is_category('3') ) { ?> <?php include (TEMPLATEPATH . '/sidebar3.php'); ?> 
<?php } elseif ( is_category('6') ) { ?> <?php include (TEMPLATEPATH . '/sidebar6.php'); ?> 
<?php } else { ?> 
<?php } ?>

The above example is more or less using the same code as what I outlined in a previous post, creating multiple sidebars.

In this case, you would insert the HTML snippet wherever wanted it to appear on each sidebar file. Once you have a sidebar you can load it by the category name/id.

Leave a Reply