By hagus42 on
Hi all.
I thought I would share a simple module I cooked up. I wanted to be able to display a google ads banner beween every five entries on the front page. The way I did it was this:
Modify the node.module
In function node_page_default() I made some changes ....
$output = '';
$cnt = 0;
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1);
$cnt++;
node_invoke_nodeapi($node, 'inbetween', $cnt);
if ($node->inbetween)
$output .= $node->inbetween;
}
Create a new module called google_ads.module
<?php
/**
* Implementation of hook_nodeapi().
*/
function google_ads_nodeapi(&$node, $op='list', $cnt) {
if ($op == "inbetween" && $cnt % 5 == 0)
$node->inbetween = t("
// MY GOOGLE AD CODE HERE
");
return;
}
}
Then enable the module, and Bob's your mother's brother.
Comments
that is a good idea, thank
that is a good idea, thank you for shearing!
Excellent snippet
You might want to add this to "PHP block snippets" section of drupal.org....
Thanks,
Chris
Tech. articles with a WAMP+IIS+Drupal focus
Take a break: Guide to France