Thesis Tutorial – Advanced Ad Targeting

Since my last tutorial explaining the basics of the newly unveiled Thesis hooks was so well received, I thought I’d show you a bit more of how advanced the Thesis theme really is.

Not only will I “show” you, but I’ll also teach you how to take advantage of it on your own personal or professional blog.

If you look at my site, you’ll notice I run a large graphical ad above the fold on the Sugarrae website:


Ok, big deal Rae… we already know Thesis can use more custom ad targeting than most themes and that you can specify specific ads on a page by page basis:

Imagine you own an SEO blog but get a lot of traffic from people searching for routers due to a one off post you did… with Thesis, you can change your advertising on that single page to be router related without forcing you to rely on webmaster welfare to do it for you. – Source

And it is one of my favorite features about Thesis. You didn’t need to pick one “sitewide ad”. But after implementing “post specific” ads heavily, I needed to change a “non converting” ad. The problem was that I had to change the ad on every individual post (and good luck on remembering exactly which pages have which ads if you have several hundred posts).

Additionally, there was no way to specify an ad on a specific category page. It always showed the “sitewide” ad by default. While my blogging category page would do well showing an ad for the Thesis theme, my affiliate marketing category page would likely do better showing an ad for Linkshare or Pepperjam.

What I wanted was the ability to:

  • Specify a specific ad for each individual category page on my blog
  • Have posts filed in each category show the “category ad” for its category by default
  • Still be able to override the default ad on a single post if I choose

For example:

And by using hooks, I’m able to do all of the above. And now you can too.

Example: Specifying Custom Category Ads

Let’s say you want to show an ad for Acme Lightbulbs on the main page of your lightbulbs category and have that ad be the default ad for all single posts in the lightbulbs category. You also want to show an ad for Granny Apples in your apples category and have that ad be the default ad for single posts in the apples category. On all other site pages, you want to show an ad for Thesis.

Step 1: Upload the graphics you want to add to show up in your multimedia box to the custom images folder (thesis > custom > images > put your image here)

Step 2: Open your custom_functions.php file (thesis > custom > custom_functions.php) in your favorite editor

Step 3: Underneath the example code already in the file, place the following code (this code assumes your blog is in the root):

/* Multimedia Box */
function custom_ad_box() {
$categories = thesis_get_categories();

if ($categories) {
if (is_category('lightbulbs') || in_category($categories['lightbulbs']))
lightbulb_ad();
elseif (is_category('apples') || in_category($categories['apples']))
apples_ad();
else
generic_ad();
}
}

function thesis_get_categories() {
$raw_categories = &get_categories('type=post');

if ($raw_categories) {
$categories = array();

foreach ($raw_categories as $category)
$categories[$category - >slug] = $category - >cat_ID;

return $categories;
}
}

add_action('thesis_hook_multimedia_box', 'custom_ad_box');

The /* Stuff Inside Here */ is a label for the code below so you know what it is at a single glance. This is not part of the actual “code”. The word “function” tells Thesis you want it to do something. The custom_ad_box is what I decided to name that function.

The code underneath it basically says if that category is lightbulbs (the name you enter here is based on the “slug” of your category. So if your category url is www.domain.com/category-here/ then you would enter “category-here” without the quotes in place of “lightbulbs”) then the category should show the ad named “ad_lightbulb” (we’ll define how to create your ad next). – “if is_category”

If the category is not lightbulbs, then it will check to see if the category is apples and if it is, it will show the ad named “ad_apples”. – “elseif is_category”

If the category is not any of those defined in the code (in this case, lightbulbs and apples) then it will show the ad named “generic_ad”. – “else”

The second function in the above code, which is function thesis_get_categories is generic and should not be changed. The only changes you need to make are to the category names and names of the ads to be shown or adding additional “elseif is_category” lines.

The add_action('thesis_hook_multimedia_box', 'custom_ad_box'); line tells Thesis that you want it to add a function in the multimedia box and the function you want to add is the one we just created – the custom_ad_box function.

Now that Thesis knows what ad name to show on what categories, we need to define the ads themselves.

/* Custom Ads */
function lightbulbs_ad() {
?>
<a href="http://www.LINKLIGHTBULBADISLINKEDTOHERE.com/"><img src="THE-URL-OF-YOUR-LIGHTBULB-AD-IMAGE-GOES-HERE"></a>
<?php
}

function apples_ad() {
?>
<a href="http://www.LINKAPPLESADISLINKEDTOHERE.com/"><img src="THE-URL-OF-YOUR-APPLES-AD-IMAGE-GOES-HERE"></a>
<?php
}

function generic_ad() {
?>
<a href="http://www.LINKGENERICADISLINKEDTOHERE.com/"><img src="THE-URL-OF-YOUR-GENERIC-AD-IMAGE-GOES-HERE"></a>
<?php
}

As with before, the /* Stuff Inside Here */ is a label for the code below so you know what it is at a single glance. This is not part of the actual “code”. The word “function” tells Thesis you want it to do something. In this case, we’re defining three “functions” which are ads to be used in the custom_ad_box function we already defined above we decided to name lightbulbs_ad, apples_ad and generic_ad. Just put the HTML for whatever you want to appear in that ad slot there:

function name_of_ad() {
?>
HTML HERE
<?php
}

I first defined what ads should appear where and then defined the ads themselves underneath. However, if you find it easier, you can always define the ads first and then define where they should appear second. The order doesn’t matter as long as you both define the ads and in what categories they should appear.

That said, please note that if you were previously using the “custom code” option in the Thesis options panel, and there is code in there currently, you will need to remove the code and hit the big ass save button to see your new ad hooks display.

You can override the default ad shown for any category on a single post basis the same way as before:

I’m able to override the base choice I’ve made of what to show in that area for the majority of my site pages/posts in the Thesis control panel, all without ever having to touch a drop of code in the WordPress templates by utilizing the custom key option on the specific page or post.

If you view the photo above, you’ll see I was able to select the “custom” key I defined in the Thesis control panel and “override it” and insert specific code to replace the normal “custom” key, only for this post.

If you’re still not using Thesis, get on board. This is the first of many cool tutorials I’ll have coming in the next few months that show why Thesis is quickly moving from being the “best theme choice” for a professional blog to being the “only choice”.

About Rae Hoffman

Rae Hoffman aka "Sugarrae" is an affiliate marketing veteran and the CEO of PushFire, a search marketing agency specializing in SEO audits and link building strategies. She is also the author of the often controversial Sugarrae blog. You can connect with Rae via Twitter, Google+ and Facebook.

Sugarrae runs on the Genesis Framework

Genesis Framework

If you’re someone who doesn’t understand a lot of PHP, Genesis will give a ton of functionality that you wouldn’t be able to obtain otherwise with a simple control panel instead of having to alter code. For the advanced, Genesis has incredible customization possibilities via Genesis hooks.

The theme is not only highly customizable, but it has allowed me to run Sugarrae more professionally, with a much more targeted focus on monetization than it ever has been able to achieve before.

You can find out more about Genesis below:

Speak Your Mind

*