·  News ·  Travel ·  Food ·  Arts ·  Sciences ·  Sports ·  Advice ·  Religion ·  Life ·  Greensboro · 

Adsense for PHPBB 3.0 - Inline & First Post

User avatar
by I show you something fantastic and you find fault.
Published on April 6th, 2007, 12:52 pm
Rift: Advice
  
Welcome to the latest incarnation of Adsense for PHPBB 3.0 Olympus.

This Adsense Modification works differently than other codes you've seen posted as it checks to see if the dynamic page being generated is a post or a topic. If it's a post it doesn't show the ad. Why? Because generally most of the time the only reason a reader will be on a post page is when they've just replied, or edited a page. They've already seen the ad. Because each post generates an individual URL for each post, the viewer will only be seeing a single untargeted ad. The bot which will later come by and download the page wastes bandwidth, and since it's unlikely the page will be ever served again, we turn it off. This increases your CTR, and benefits you by increasing the value of your AdSense landing pages.

This of course doesn't address your index, or viewforum, but a similar approach could be made. Since most of the revenue seems to come from the topic pages themselves, this is a perfect approach.

To use this code, just follow the instructions below, and replace the pub-id in the AdSense code currently (12345) to your own:

Change this, in the code below:
Code: Select all
google_ad_client = "pub-12345";


Should take you all of 5-10 minutes to get this working. You may also choose to adjust the IP to block ads to yourself.

The latest addition is the code that disables the AdSense on users with greater than a 3 posts. You can change the 3 in the code to the number you like, and at users with post counts greater than that number receive no ads.

Open Viewtopic.php and find:
Code: Select all
// Send vars to template


Before that line add this:
Code: Select all
// ADSENSE for PHPBB 3.0 by Liv Jones - February 7, 2010
// Support for this modification can be found at:
// http://greensboring.com/viewtopic.php?f=23&t=4299

// BEGIN ADSENSE CODE

if (empty($_REQUEST['p']) && empty($_REQUEST['sid']) && empty($_REQUEST['hilit']) )  {

$adsense=<<<EOD
<script type="text/javascript"><!--
google_ad_client = "pub-12345";
google_ad_width = 300;
google_ad_height = 250;
google_ad_format = "300x250_as";
google_ad_type = "text_image";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "000080";
google_color_text = "000000";
google_color_url = "DDDDDD";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
EOD;

$adsense2=<<<EOD
<script type="text/javascript"><!--
google_ad_client = "pub-12345";
google_ad_width = 300;
google_ad_height = 250;
google_ad_format = "300x250_as";
google_ad_type = "text_image";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "000080";
google_color_text = "000000";
google_color_url = "DDDDDD";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
EOD;

if (isset($user->data['user_id']) && $user->data['user_id'] != 1 && isset($user->data['user_posts']) && $user->data['user_posts'] > 3) {          $adsense='';
          $adsense2='';      
}
}

//block self
// change to your IP to block ads to yourself and prevent accidentally clicking on them.

$self="24.148.149.208";
if ($_SERVER['REMOTE_ADDR'] == $self) {
$adsense='';
$adsense2='';
}
//block self

// block certain forums
if ($forum_id == 27 || $forum_id == 28) {
$adsense='';
$adsense2='';
}

// Licensing:
// Please help a girl and her family out by providing a link for using this script even if you remove this line.
$adsense=$adsense.'<br><small><small><small><a href="http://greensboring.com/">Ad Software by Greensboring.com</a></small></small></small>';


$template->assign_vars(array('AD_SENSE' => $adsense, 'AD_SENSE2' => $adsense2));

// END ADSENSE FOR PHPBB MOD


Open your viewtopic_body.html Template in the ACP, and add this in your template where you want the ad to appear. I prefer the 300x250 ad inside the first post. This can be done by searching for this:

Code: Select all
{postrow.MESSAGE}


And Above it (or right before it) add this:

Code: Select all
<!-- IF postrow.S_FIRST_ROW -->
<div style="float:left;">
{AD_SENSE}
</div>
<!-- ENDIF -->


You can also use the second Adsense variable else where in your template such as below the posts, such as:

Code: Select all
{AD_SENSE2}
April 6th, 2007, 12:52 pm   Share
 
Thanks for your support it work pefect. :)
October 6th, 2007, 1:55 pm
amko77
 
Posts: 2
Joined: October 5th, 2007, 5:52 pm
Hi, thanks for this great Plugin it worked perfectly for me. =(

But somehow i screwed it up and i can't figure out how.
The only thing i changed was installing a languagepack (which has a viewtopic of its own, just as the default "en" languagepack). Could this be a reason for it to not work anymore? I would appreciate your help very much.
Thanks again
January 23rd, 2008, 7:04 am
Benjamin
 
It may have deleted the {AD_SENSE} in your template...

Not sure... I still use the GB template, ala meta info changed to american
January 23rd, 2008, 9:12 am
User avatar
Liv
I show you something fantastic and you find fault.
 
Posts: 10596
Joined: October 5th, 2005, 1:59 pm
Location: Greensboro, NC
New to PHPBB and I can not find the document you mean by "viewtopics" template near the bottom of your how to. Sorry to be think and I will gladly add you to my links on various sites.
February 1st, 2008, 4:33 pm
woodyman
 
It should be in the root folder of your PHPBB install....

You'll see index.php, viewforum.php, etc.... and viewtopic.php

It can't be done from the template editor.... You'll need to access it via ftp, and then download it... open it with wordpad and make the modifications.
February 1st, 2008, 4:36 pm
User avatar
Liv
I show you something fantastic and you find fault.
 
Posts: 10596
Joined: October 5th, 2005, 1:59 pm
Location: Greensboro, NC
Sorry I was not clear. I got that one ok the one I can not find is the "viewtopics" in the ACP. My ACP does not have a a viewtopics.php.
FOR I AM CONVINCED neither life nor death, neither angels nor demons, nor powers, not things present nor things to come, nor height nor depth, nor anything else in all creation can separate us from the love of God which is in Christ Jesus our Lord. Romans 8:38-39
February 1st, 2008, 4:55 pm
jwoodyu
 
Posts: 2
Joined: February 1st, 2008, 4:30 pm
It's viewtopic_body.html in the Style section of the ACP... sorry.
February 1st, 2008, 6:06 pm
User avatar
Liv
I show you something fantastic and you find fault.
 
Posts: 10596
Joined: October 5th, 2005, 1:59 pm
Location: Greensboro, NC
I have just installed and upgraded to PHPBB 3.0 and I followed your codes to the letter..

TOO BAD THEY DON"T WORK!.!

I get NOTHING!

Nice try though! Seems like nobody has a AdSense code that works for 3.0 I guess I will go back to 2.0, at least you can put AdSense in that one.
February 7th, 2008, 9:42 am
ktnet
 
Posts: 3
Joined: February 7th, 2008, 9:37 am
This same code is running on this site, and is 3.0... Check your database prefix and make sure it matches.... otherwise post your error, and I'd be glad to help you troubleshoot...

Numerous other boards also run my code....
February 7th, 2008, 10:06 am
User avatar
Liv
I show you something fantastic and you find fault.
 
Posts: 10596
Joined: October 5th, 2005, 1:59 pm
Location: Greensboro, NC
Well, There are no error codes or message. It just does not show anything. NOTHING!

I put the codes just as you have them, I even double checked them.

I just don't get it. I can tell you that when I put them in with FrontPage, the code showed up RED and the topic page showed up blank.

Thanks for your response.
February 7th, 2008, 2:45 pm
ktnet
 
Posts: 3
Joined: February 7th, 2008, 9:37 am
Ktnet, you were right... I couldn't find the code problem, but I tried putting it on a fresh install and it buggered out.... Must have been from a code change that I didn't test... and rather then hunt it down, I updated the page with the latest.... So... It's been updated... You can try it now... I also just ran a test online with the following files and it ran brilliantly....

Good Luck!
February 7th, 2008, 7:59 pm
User avatar
Liv
I show you something fantastic and you find fault.
 
Posts: 10596
Joined: October 5th, 2005, 1:59 pm
Location: Greensboro, NC
I do see it blank... although I have no clue as to why...

The first thing I'd do is clear your cache, if you haven't already.... See if that works...

The next thing I'd check is how the files are being:
a) edited
b) uploaded

I had a problem with old versions of Windows XP saving the files minus the "line breaks" for some time.... Which sort of resulted in he same thing... Try uploading those two files without modifying them and see if it works.
If it does, then you need to find another text editor....

If that isn't it... I'd check your upload settings on your FTP agent. Try 8-Bit Binary, etc...

Lastly I'd try starting over if all else fails, since I assume your PHPBB install works with the "original" files, I'd go an option of trying a simple adsense code like:

Code: Select all
$adsense=<<<EOD

STICK CODE HERE

EOD;


and the rest the same... etc...

Code: Select all
'AD_SENSE' => $adsense,



and add

Code: Select all
{AD_SENSE}


into your template..


Thats all I can think of for now... if that doesn't work then I'm not quite sure what's going on...

It "should" work just uploading those files, and clearing your cache....
February 9th, 2008, 3:24 pm
User avatar
Liv
I show you something fantastic and you find fault.
 
Posts: 10596
Joined: October 5th, 2005, 1:59 pm
Location: Greensboro, NC
Hello again!

I just wanted to say you are my hero :D

I cleared the cache, and it worked for me :!:

Thanks for puting up with me, now I would like to know how you got the little tabs at the top here likes to "googlevideo", ifilm", "youtube" and others.

Also can you create that for...... like photoshot and other photo sites?

Thanks again!

Karl
February 15th, 2008, 9:21 am
ktnet
 
Posts: 3
Joined: February 7th, 2008, 9:37 am
No problem... Yes... The youtube buttons (or other services) are customizable under your control panel... Click on Posting->BBCodes->Add New BB Code....

Basically you just replace the variables (the stuff that's going to change) with {TEXT1} {TEXT2) etc.....

Here's the youtube I use for example:
Code: Select all
[youtube]<object width="{TEXT1}" height="{TEXT2}"><param name="movie" value="{TEXT3}"></param><param name="wmode" value="transparent"></param><embed src="{TEXT4}" type="application/x-shockwave-flash" wmode="transparent" width="{TEXT5}" height="{TEXT6}"></embed></object>[/youtube]


and in the second box (HTML replacement)

Code: Select all
<object width="300" height="250"><param name="movie" value="{TEXT4}"></param><param name="wmode" value="transparent"></param><embed src="{TEXT4}" type="application/x-shockwave-flash" wmode="transparent" width="300" height="250"></embed></object>


Thats all there is too it... It takes a while to get used too... but once it's set up it's so much better the PHPBB 2.0
February 15th, 2008, 12:39 pm
User avatar
Liv
I show you something fantastic and you find fault.
 
Posts: 10596
Joined: October 5th, 2005, 1:59 pm
Location: Greensboro, NC
Clearing the cache definitely does it
March 30th, 2008, 10:43 am
dacoatne
 
I'm trying to install this plugin, but I'm having errors all over the place. It keeps throwing up

"Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in"

At first just on the lines relating to selectively displaying the adds depending on user post count, but now throughout the code.

I know I'm not giving the most complete data here, but if you let me know what to look for, I'll see what I can get you!

Also, thanks for making this plugin, its just what I need.
April 11th, 2008, 11:30 am
Kai Davis
 
Being in London, I'll guess you may have deleted or added quotes where they shouldn't be...
April 11th, 2008, 5:49 pm
User avatar
Liv
I show you something fantastic and you find fault.
 
Posts: 10596
Joined: October 5th, 2005, 1:59 pm
Location: Greensboro, NC

Return to Advice