Sourcefabric Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Newscoop 4.3 Cookbook

Working with advertising

Generating revenue with advertisements usually means including code from advertisers or ad networks in your pages. In Newscoop this means incorporating ads in an existing template, or creating special templates for different campaigns. As shown in this Cookbook, there are many ways you can make content related decisions on which advertisement to include, for example based on article type, keywords, topics, section and so on.

At the end of this chapter you'll find a suggestion about how to handle your own banners. But first, let's look at external providers.

Include insert codes from a local OpenX server

Using insert codes from OpenX is quite easy. Once you have OpenX installed, you will need to define what they call "zones" for your advertising. Once defined, you can copy and paste the resulting insert code into your template. Here is a sample script for including a banner ad served from OpenX:

<script type='text/javascript'><!--//<![CDATA[
   var m3_u = (location.protocol=='https:'?'https://openx.YOURSITE.COM/delivery/ajs.php':'http://openx.YOURSITE.COM/delivery/ajs.php');
   var m3_r = Math.floor(Math.random()*99999999999);
   if (!document.MAX_used) document.MAX_used = ',';
   document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
   document.write ("?zoneid=66&amp;target=_top&amp;charset=UTF-8");
   document.write ('&amp;cb=' + m3_r);
   if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
   document.write ('&amp;charset=UTF-8');
   document.write ("&amp;loc=" + escape(window.location));
   if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
   if (document.context) document.write ("&context=" + escape(document.context));
   if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
   document.write ("'><\/scr"+"ipt>");
   <a href='http://openx.YOURSITE.COM/delivery/ck.php?n=a16e8b28&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_top'>
   <img src='http://openx.YOURSITE.COM/delivery/avw.php?zoneid=66&amp;charset=UTF-8&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=a16e8b28' border='0' alt='' />

For more info on OpenX, check their documentation at

Include insert codes from Google AdSense

Once you have successfully created a publisher account with Google AdSense, you can copy and paste the insert code into your template with your publisher ID and ad slot info. Here is an example:

<script type="text/javascript">
   google_ad_client = "pub-XXXXXXXXXXXXXXXX";
   /* 300x250, created 6/25/09 */
   google_ad_slot = "YYYYYYYYYY";
   google_ad_width = 300;
   google_ad_height = 250;

<script type="text/javascript"

You can find out more about Google AdSense at

Handling banners in Newscoop templates

You can also build your own logic for banner ads in your site. In the following example we will display different banners in different sections.

1. Create banner templates

Inside the folder of your template pack, create a new folder _banners. In this example we are building banners for the "Ushahidi Cooker" so the folder path is:


Inside this folder, create template files with banners. There is no Newscoop code inside these templates, just simple HTML displaying a banner with link or embedding a Flash banner - anything you like, we won't explain how to do these. In our example the banner templates are named:

  • banner_hospitals.tpl
  • banner_libraries.tpl

2. Create a template to handle the banner display

Inside the same folder, create a file called check_banner.tpl. This file contains code similar to the following (adjust it for your publication):

{{ if $gimme->section->number == 10 }}
  {{ include file="_banners/banner_hospitals.tpl" }}
{{ /if }}
{{ if $gimme->section->number == 11 }}
  {{ include file="_banners/banner_libraries.tpl" }}
{{ /if }}

This template can be extended to cover more sections.

3. Include the master banner

Now all you need to do is include the check_banner.tpl template in your publication at the place where you want to display banner ads:

{{ include file="_banners/check_banner.tpl" }}

Using the Newscoop template language, you can modify the IF condition any way that fits your publication's needs.

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.