You might notice a rash of Drupal-related posts over the next couple of weeks. Last week, we decided to port the site over to that very popular CMS, mostly because we outgrew WordPress in about 3 days. Don't get me wrong, I love WordPress for straight bloggin', but it's a little limited on the pure CMS side of things. Still would recommend it to anyone who just needs a blog, though (I still use it for my personal stuff).
Anyway, today I installed the AdSense Injector module (Nerd's gotta eat, right?) after reading about it on the Drupal site. We'd previously added some AdSense blocks, but I liked the way the AdSense Injector module claimed to insert the ads in more visible locations (like the one you saw at the beginning of this article).
So I downloaded the module, unpacked it, activated it, set it up, refreshed a page... and nothing. No new ads.
A little investigation quickly pointed out the problem: AdSense Injector assumes you have a Body field in your content type. Unfortunately, our articles are written using a customer content type created with the absolutely essential Content Construction Kit (CCK) module. Furthermore, to have more granular control stylizing our template, we've removed the normal body module and replaced it with a custom field. Seems the AdSense Injector module didn't like that.
The good news is that the AdSense Injector module is pretty straight-forward, so editing the module to fit our needs was simple. All we had to do was modify the adsense_injector.module file in a few places to look for our customized field and voila! You can now see (and, hopefully, click) the well-placed Google AdSense ads at the top and bottom of each post.
The specific lines we changed were:
Line 81
Before:
$oldBody = $node->content['body']['#value'];
After:
$oldBody = $node->field_article_body[0]['value'];
Lines 92-93
Before:
$node->body =
$node->content['body']['#value'] = strtr($template, array('%body' => $oldBody));
After:
$node->field_article_body[0]['value'] = strtr($template, array('%body' => $oldBody));
Line 95
Before:
$node->content['body']['#value'] = "<!-- adsense_injector: node body word count ($wordcount) is insufficient ($minwords required), so we won't insert an ad. -->" . $oldBody;
After:
$node->field_article_body[0]['value'] = "<!-- adsense_injector: node body word count ($wordcount) is insufficient ($minwords required), so we won't insert an
ad. -->" . $oldBody;
Couple things to keep in mind...
First, your changes will obviously depend on how you have your custom content type configured. My field is called field_article_body. Yours probably isn't. Adjust accordingly.
Second, I'm only using this for node body ad insertion and only with this one custom content type. If you want to use it with node list ad insertion or with other content types, again, you'll need to make more adjustments to the code.
If we do end up needing to use this modules for other content types and the creators don't give you more control in a future release, I may modify it to me more easily changed (that is, through the admin control panel rather than by editing the underlying PHP). If there are others out there looking for that kind of support, definitely speak up.
Good work
Thanks for coming up with suggestions for a solution. I'm glad you like AdSense Injector, despite the CCK shortcomings.
I have found AdSense Injector to be very helpful on many of my sites - in fact, I can't live without it. It's due for an overhaul, though, and the CCK issue is something I need to deal with.
In any case, patches always welcome!
Post new comment