Here's an example:
By taking the naive approach and just adding the AdSense code to the entry-default.tpl file will violate the Google policy for placing ads. The policy is quite strict and has limits on how many ad units are permitted per page. Without additional code in the template, the AdSense content will get repeated over and over.
The rules for displaying or not displaying the AdSense code are like this:
- Do not show on the main blog page
- Do not show on the categories list
- Do not show on any other blog page listings (page 2, page 3, etc)
- Show on the entry page
With the above rules in mind, I wrote the following code:
{php}
if (substr_count($_SERVER[REQUEST_URI], "index.php/") > 0 AND
substr_count($_SERVER[REQUEST_URI], "/category") == 0 AND
substr_count($_SERVER[REQUEST_URI], "/page") == 0) {
{/php}
<div class="adsenseentry">
...
</div>
{php}
}
{/php}
Instead of the ellipsis (...), I have my actual AdSense code from Google (omitted here).
This code assumes that the pretty URLs plugin is used and the .htaccess is set up correctly. It will not display the AdSense content for category and page listings, but only for the entry page itself.
-i