January 20th, 2006
Zen Minimalist Theme and Adsense
Sometimes, minimalism can be taken a bit far. So far, in fact, that it becomes difficult to add Adsense to the blog. Maybe it’s just me, but I like having separate channels for my ads on the index page and those in post - even if the ad sizes are similar. To me, it’s pretty useful in tracking the performance between your index page and your posts.
When we come to the Zen Minimalist theme, which this blog happens to be based on, doing so becomes difficult because of the lack of a post template. Almost all WordPress themes separate the templates for the main index page and for individual posts, but hyperminimalist themes like this can sometimes lack a separate post template.
Normally, this doesn’t bring too many problems, but when I wanted to add an rectangle-sized Adsense advert on my index (between the first and second posts) and at the bottom of my individual posts, I ended up having both ads showing at the bottom of my individual post pages. Note: I’m no pro, so to place the advert at the bottom of each post, I added the code in the comments template (due to the lack of a post template). And because the index page template served also as the individual post template, two ads were shown (one from the index, the other from the comments).
So, the solution I took was to remove the advert placed in the comments template. As such, only the index page advert would show on the individual post page.
The problem is: the Adsense channel used to track both the index and the individual posts would be the same. One way to solve this would be to write an individual post template for the Zen theme (making all the prior problems obsolete). But lazy as I am, I decided to use a minimalist approach and use simple conditional tags for the Adsense code. Basically, what this does is to use a particular Adsense code (with channel code A) when you are looking at the index page, and use another Adsense code (with channel code B) on all other pages (including the individual posts).
I stole the original code to display an advert between the first and second posts on the main page from the WordPress Codex. Check that for the original implementation.
Then, what I did was to just add a simple WordPress conditional tag known as the is_home() tag.
Original Code:
<?php if ($postnum == $showads) { ?>
AD CODE with Index Page Channel here
<?php } $postnum++; ?>
Modified Code:
<?php if ($postnum == $showads) { ?>
<?php if ( is_home() )
{
echo ‘AD CODE with Index Page Channel here’;
}
else {
echo ‘AD CODE B with Other Pages Channel here’;
}
?>
<?php } $postnum++; ?>
So, we end up with a minimalist modification for a minimalist theme. Is there an even more minimalist way of doing this?
If you found this post useful, keep updated with future posts by subscribing to blogHelper (for free) through RSS or email.















Leave a Reply