21.11. How to show advertisements in PHP-Nuke modules

So now you have seen how nice your new AdSense block (Section 20.7) looks and you've got appetite for more? Here you are:

21.11.1. Google AdSense in the News module

Wouldn't it be nice to have your Google AdSense placed just right to a news article? The solution we will present here, taken from Google AdSense in PHP-Nuke, can be used as a starting point for introducing AdSense (and other similar advertisement schemes) in modules other than the News module.

In file modules/News/article.php, look for the following code:

$boxtitle = ""._RELATED."";
$boxstuff = "<font class=\"content\">";
$sql = "select name, url from ".$prefix."_related where tid=$topic";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
$name = $row[name];
$url = $row[url];
$boxstuff .= "<strong><big>&middot;</big></strong>&nbsp;<a href=\"$url\"
target=\"new\">$name</a><br>\n";
}

just before that, add the following:

echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" bgcolor=\"#FFFFFF\"
width=\"160\"><tr><td>\n"
."<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"160\">\n"
."</table>\n"
."<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" bgcolor=\"#FFFFFF\"
width=\"100%\">\n"
."<tr><td align=\"center\">\n"
."<font class=\"title\" size=\"1\"><b>Related Websites</b></font>\n"
."</td></tr>\n"
."<tr>\n"
."<td bgcolor=\"#FFFFFF\"><font size=\"1\">";
?>
<center>
<script type="text/javascript"><!--
google_ad_client = "your client-number";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = "120x600_as";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "336699";
google_color_url = "000000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</center>
<?php
echo "</td>\n"
."</tr>\n"
."</table></td></tr></table>\n"
."<br>\n\n\n";

In the above code, you can recognize the Google AdSense Javascript, also used in Section 20.7 to show AdSense in a PHP-Nuke block, in the middle of a table layout construction.

ImportantDon't forget:
 

Add your Google client number in the AdSense script.

21.11.2. Google AdSense on top of a PHP-Nuke module

If you would like to add a 728x90 banner on top of every module, you can include the AdSense Javascript code in a separate file, call it adsense.php, then just include this file from your module (you can also choose a 486*60-banner if you like):

Put the following code in includes/adsense.php:

<center>
<script type="text/javascript"><!--
google_ad_client = "your client-number";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "336699";
google_color_url = "000000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</center>

This is nothing else but the well-known Google AdSense Javascript code we have also encountered in Section 20.7 and Section 21.11.1. Once you have adsense.php in the includes directory, it becomes trivial to use its code in any module you choose: for every module you would like to add the Google AdSense to, look for the following code:

include("header.php");

and place the following line after that:

include("includes/adsense.php");

TipMake some room for long banners
 

Make sure that your module contains the line

$index = 0;

(not necessary if you use 468*60), otherwise you will get the right blocks column too - and this is not nice with a 728*90-banner.

TipLong AdSense banner in the News module
 

The right place to put the Google AdSense long banner in the News module, is in the modules/News/index.php file,. There, find the line

$topic_title = $row_a[topictext];

and add the line

include("includes/adsense.php");

directly after it (see Google AdSense in PHP-Nuke).