Home > Technical stuff > add targeted ads from Chitika in WordPress

add targeted ads from Chitika in WordPress

I have just added adds from Chitika. They can do targeted ads just like Google AdSense, but in the Google AdSense contract you are forbidden to use that with another ad company if they use targeted ads. But there’s a way of manually add the stuff that’s supposed to show in the ads from Chitika. But that involves editing the index.php and then add that search word in the javascript variable called ch_query. But wouldn’t it be great if you could use the Custom Fields that’s already in WordPress? Well you can. And here’s how I did it. When writing your blog posting, just add a tag called “ad” in the Custom fields, and then put the search word you want, for example “ipod”. I’ve put the code so that WordPress uses the the codes when displaying a single post. So if you write a posting about photography, you can add an “ad” tag with “canon eos” or similar, and be certain only relevant adds be shown. If there’s no custom field with an “ad” entry, it just displays a Google AdSense ad instead.


Get Chitika eMiniMalls

The code ain’t pretty, but it does the job.

You need to open your index.php found in /wp-content/themes/yourtheme and look for:

if ($single && (empty($post->password) ||
$HTTP_COOKIE_VARS['wp-postpass_'.$cookiehash] == $post->post_password)) {

And add the following code (after editing the outlined parts of the code) after that. Then the targeted ad will only show up when someone clicks on a specific posting.

<?php
$adkey = get_post_meta($post->ID, "ad", FALSE);
if (!$adkey) {
    /* No ad keyword, so display Google ads. */
   
    /* ADD GOOGLE OR OTHER CONTENT HERE IF NO DIRECT AD TAG */
    ?>

<?php
    }
else {

    /* Now lets add the Chitika code here. */
    /* All Custom Fields with tag 'ad' will be used */
    ?>
   
    <script type="text/javascript"><!--
    ch_client = "Your client id here";
    ch_width = 468;
    ch_height = 60;
    ch_nosearch = 1;  // Remove search tab to comply with Google Ads
    <?php
    /* Now take all custom fields*/
    srand(time());
    $adrnd = rand(0,count($adkey) - 1);
    print("var ch_query = '$adkey[$adrnd]';");
    ?>
    //--></script>
    <script  src="http://scripts.chitika.net/eminimalls/mm.js" type="text/javascript">
    </script>

    <?php
    }

After adding and modifying the code to suit your needs, you need to go and add some tags. Go to the admin pages of WordPress and edit postings. You can have several tags per posting.

Add Tag Wp

Here I have added three different ads. The ads will be randomly selected automatically.

Now try to load the posting in question.

You should now have a more flexible ad system, and it’s easy to update as well.

Categories: Technical stuff Tags:
  1. October 12th, 2005 at 23:22 | #1

    One suggestion : when posting code, use for example http://priyadi.net/archives/2005/09/27/wordpress-plugin-code-autoescape/
    Otherwise it’s just impossible to cut&paste your code with all these curly quotes and stuff :)

  2. Jacken
    October 12th, 2005 at 23:39 | #2

    Thanks Ariane! That fixed the problem.

  3. October 13th, 2005 at 04:35 | #3

    That’s very interesting (I think I’ll trackback this entry soon). I only wonder if the additional work (specifying ad terms) is worth that little investment. AdSense is about ‘autonomousity’.

  4. October 13th, 2005 at 07:57 | #4

    Roy : it’s not adsense, it’s chitika. And to use Chitika along with Adsense, you have to make chitika ads non contextual, i.e. not let it pick a keyword from your page content. Therefore you have to feed it with keywords yourself.
    For more info on Chitika ads and how to hack them, refer to my guide : Chitika tips, tricks and hacking guide

  5. October 16th, 2005 at 02:44 | #5

    Excellent!
    I had to tinker the code a bit a bit to suit my needs, but nothing extreme.
    Thank you for sharing!

  6. January 30th, 2006 at 04:10 | #6

    Jacken,

    I recently signed up for Chitika and was looking for something just like this! Thanks for providing the code, works and looks great on my site. I love the ability to customize the product for each post.

  7. February 16th, 2006 at 04:27 | #7

    im using adsence on my website http://www.pixelmerge.com but im not getting hits. why doesnt anyone visit?

  8. zach shine
    May 26th, 2006 at 08:58 | #8

    DataFeedFile.com has a Chitika alternative…

    I found this site because I was kind of po when I received a rejected email from Chitika… so I went searching for alternatives.

    Chitika turned me down due to not enough traffic on my blog. Fortunately I found a similar service based on a much more fair and open market. DataFeedFile.com is a similar service with much more options and banner sizes to choose from.

    What I like about DataFeedFile.com is they allow you to choose what merchant to display products for. DataFeedFile.com seems to be a colaboration of hundreds of merchants from the affiliate industry. Check them out yourself, http://www.DataFeedFile.com.

    Zach Zach

  9. June 24th, 2006 at 20:21 | #9

    nice plugin, thanks for work, more plugins for wordpress here : Word press and here P-Lugins

    and custom themes here: Wordpress themes download

  10. May 5th, 2009 at 20:51 | #10

    nice

  1. November 7th, 2007 at 21:13 | #1
  2. April 13th, 2008 at 05:52 | #2
  3. April 25th, 2008 at 23:26 | #3

Jacken’s Blog is Digg proof thanks to caching by WP Super Cache!