x
 
Create New Page

Revision: Ad banners in discussion module

Revision from: 14:37, 30 Apr 2008

Keywords: Openads, adverts, separate ads in different forums, forum ads, discussion module banner ads

Problem: The discussion module works off of one main template, theme_global.php in the forum themes directory.

A user who wishes to place general google ads or rotating ads from a program or script can usually simply insert the Javascript banner ad code in certain places, most likely:
1. In the page sub-header (for top banner)
and
2. In the HTML footer - near the bottom of that code before the last body (end) tag.

But neither of these solve the problem of placing different ads in different forums! For instance, if you have a site on remodeling, and have three forums:
A. Roofing
B. Electrical
C. Plumbing

It would be nice to be able to offer ad programs to your sponsors in their targeted forums. That would give you more inventory to “sell”, and also keep the sponsor happier.

Here is the solution that I hacked together for beginners. Please feel free to improve or add to this and/or email me.

Going a bit further, we need code that will allow us to assign sponsors to particular forums, but also allow google ads (or other default ads) to show up when there is not a sponsor!

Ok, so without further ado….this needs to be between Javascript tags.

<!--
google_ad_client = "pub-3514144mygoogleid";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
//2007-12-08: Forum Channel Header
google_ad_channel = "123654myadchannel";
//-->

var myForumString = "{path:rss}";
var
myFSResult = myForumString.split("/");
[removed](myFSResult[7]);

function
staticLoadScript(url)
{
document
. write('<\/script>');
}

if (myFSResult[7] >= 2)

{
staticLoadScript
("http://www.hearth.com/cgi-bin/goldt" + myFSResult[7] + '.' + "pl?jscript");
}
else
{
staticLoadScript
("http://pagead2.googlesyndication.com/pagead/show_ads.js");
}

Note that the spaces between the document-write command must be removed! Leave the period.

How it works:
The code at the beginning of the script sets up the google ads in case we decide to use them (further down).
The line with the path:rss simply grabs the path of your server - in this case a URL like:
http://www.hearth.com/econtent/index.php/forums/rss/22/

The /22/ is the key to the city!
So the next 2 lines chops off the 22, it being the 7th segment of the URL, and then assigns it to a variable.

Then the function places that variable into a URL string which calls the banner program on your server. In my case, I use Adverts, which allows me to simply call a separate copy of the ad serving script named:
—- http://www.hearth.com/cgi-bin/goldt22.pl?jscript—-

See the forum name appended to the end of the script name?

Then there is a code which says “if the forum number is greater than 2, load up the corresponding ad script - if it is not, continue and load the rest of the google ad code. This assures that some ad (the goggle) will be called on those in-between pages like the front forum page and members profiles, etc.

Google gives that code out for their adsense program, so you don’t need to write it!

The space before and after the period between document and write must be removed.
This script works with the URL which is made up for the rss or atom feed, and sucks the number from it, for use in the url that calls the ad script.

When installing and trouble shooting this script, my suggestion is this:

1. Install it in theme_global - the main forum template, in teh Page Sub-Header, under the table HTML tags in the <div id=“subheader”>

2. RSS FEEDS MUST BE ENABLED FOR ANY FORUM YOU WANT THIS TO WORK ON. That means the bottom of your forum pages should show those little rss and atom symbols. This is turned on and off in Forum Prefs (for each forum).

3. Start out by installing a short code, like:

var myForumString = "{path:rss}";
var
myFSResult = myForumString.split("/");
document . write(myFSResult[7]);

*remember to remove the spaces after “document” and before “write”

That little code should then display the forum number on the top of your page! At least then you know you are on your way, and can use that to construct a call to your ad program. Note that this code can also be installed at the bottom of your forum pages and this can call a different ad (or zone, etc.)

Note, there is another way to get the forum_id number, but not as accurate as parsing it from the atom or rss EE tag. The forum_id is hidden in a form field inside each rendered forum page, and Javascript can get this out by a command such as this:

var MySponsor = document.forms[2].forum_id.value;

What that piece of code does is to grab the value of forum_id from the SECOND form down, counting from the top of the page. As mentioned, it is not as accurate as the above method, but some may want to consider this for various reasons.

Category:Forums Category:Advertising

Categories: