Chitika eMiniMalls on Slaptijack
Jul 10th, 2007 by Scott Hebert
I recently added Chitika eMiniMalls to Slaptijack. Since it is a violation of the Google AdSense Terms & Conditions to have other contextual ads along side Google ads, I was forced to use non-contextual ads.
Chitika eMiniMalls has a wide selection of categories that you can choose from to narrow down the selection of ads it sends your readers. Unfortunately, this means hard-coding a category, and I didn’t think readers of my TCP Performance Tuning series (a series of articles related to server performance) would want to see ads for routers.
That’s when I was hit with a stroke of genius. Instead of using one category for the entire site, I decided to use the default category and then add a query to the ad based on the category of the article being displayed. This means that an article posted in “Networking” displays routers and USB Ethernet adapters, while an article in “Graphics Design” displays ads for Adobe Photoshop.
In order to get the category from the post, the get_the_category() call must be in The Loop. That means your first bit of JavaScript (see below) must be included in all your ‘post’ pages (’single.php’, ‘index.php’, etc). Here’s the JavaScript with PHP for getting the category of the post (I’ve removed the formatting related stuff).
<!-- Chitika eMiniMall ad setup (in The Loop) -->
<script type="text/javascript"><!--
ch_client = "???"; // Your ID goes here.
ch_width = 300;
ch_height = 250;
ch_non_contextual = 1;
ch_nosearch = 1 ;
ch_query = <?php $cat = get_the_category(); $cat_name = $cat[0]->cat_name; echo "'$cat_name'"; ?>;
//--></script>
Perfect. The code that places the ad can go anywhere. For example on Slaptijack, I’ve currently got the code that places the ad in my sidebar (thus, outside the loop).
<script src="http://scripts.chitika.net/eminimalls/mm.js" type="text/javascript">
</script>
Nothing special there, just the usual stuff. Anyway, that’s what I did. Good luck!