I’m running phpBB for my site discussion forums and really like it, but I’d like to slip some advertising between forum posts #1 and #2 on my pages. For the life of me, though, I just can’t figure it out. Can you help out?
Luckily, I bumped into a fabulously detailed answer to this very question on a private mailing list, and the author, Greg Bulmash, has agreed to have it republished here at Ask Dave Taylor:
EDIT VIEWTOPIC.PHP
In viewtopic.php in the main phpBB directory, at around line 826, you’ll find:
// // Okay, let's do the loop, yeah come on baby let's do the loop // and it goes like this ... //
Right under that is the statement that begins the looping through the posts:
for($i = 0; $i < $total_posts; $i++) {
Under that I added…
if ($i=="0") { $adblock = $adblocktext; } else { $adblock = ""; }
Up near the beginning of the file, I defined the new variable $adblocktext thusly:
$adblocktext = <<<EOM <tr><td colspan=2 align=center> Insert your Google AdSense Code Here </td></tr>
<tr><td class="spaceRow" colspan="2" height="1"><img src="templates/subSilver/images/spacer.gif" alt="" width="1" height="1" /></td> </tr> EOM;
The table structure here is important. The first block puts in your Google AdSense code. The second block is a separator line.
Now, scroll down to the line 1170’ish range of the file and you’ll find a block of variable declarations that begins with:
$template->assign_block_vars('postrow', array( 'ROW_COLOR' => '#' . $row_color, 'ROW_CLASS' => $row_class,
In that block, on its own line, add:
'AD_BLOCK' => $adblock,
Save that file.
EDIT VIEWTOPIC_BODY.TPL
Now go into the templates directory, and into the subdirectory of the template you are using (i.e. subSilver). Open the file viewtopic_body.tpl for editing.
Down around line 61, you’ll find a line that says:
<!-- END postrow -->
Right above it, add the following text…
{postrow.AD_BLOCK}
Save the file, and you’re done!
Now your forums will insert whatever you wish after the first post. And yes, you can insert Javascript. I tried the following…
$adblocktext = <<<EOM <tr><td colspan=2 align=center> Insert Google Code Here <P> <script language=javascript> document.write("hoobastank"); </script> </td></tr>
<tr><td class="spaceRow" colspan="2" height="1"><img src="templates/subSilver/images/spacer.gif" alt="" width="1" height="1" /></td> </tr> EOM;
and it worked just fine.
What do you mean by “Up near the beginning of the file, I defined the new variable $adblocktext thusly:”
Where the hell is that!!!
Okay, i tried it, and then it said:
Parse error: parse error, unexpected ‘;’ in /sdc/home/shruikan/public_html/viewtopic.php on line 1412
so i undid it. and it’s still doing it! look: http://www.shruikanforums.com/viewtopic.php
Thanks for this code.
And yes, you can insert Javascript. I tried the following…$adblocktext = <<<EOM
<tr><td colspan=2 align=center>
Insert Google Code Here <P>
<script language=javascript>
document.write(“hoobastank”);
</script>
</td></tr>
<tr><td class=”spaceRow” colspan=”2″ height=”1″><img
src=”templates/subSilver/images/spacer.gif” alt=”” width=”1″
height=”1″ /></td>
</tr>
EOM;
How to use javascript i dont understand.I am begener.
is there a way to make ads appears after certain number of post.or before latest post, most people view latest posts not first ones?
I am using MorpheusXDarkBlue as my style. I couldn’t find the end post row line in the file.
Has anybody figured out how to do it using this style?
Doesnt work for me. Can anyone pls help me with details.
it worked for me too ! very nice !
very nice! Once I opened the files it took about 5 minutes to change them and then done. Great step by step guide.
Thanks for this code – it works perfectly on my site at http://www.canadahealthinfo.ca/forum.
If you are using PHP Nuke 7.9 and the integrated forum, the viewtopic_body.tpl file to edit should be the one in root of your site, in \themes\DeepBlue\forums (if you don’t then your site will appear to be doing nothing at all). This only applies to PHP Nuke installs that use the forum module pre-configured. You would also need to adjust the code for each template used. I had to do this to http://www.elitebattlemasters.com I hope it helps!!
Fish-Guy
I don’t know the internals of PHPbb but generally you can wrap the AdSense block in a div tag and use something like:
<div style=”background-color:#ccf;width:100%”>
adsense code block from Google
</div>
and that should hopefully accomplish what you seek!
Thanks for the response but I’m not actually talking about the background of the google ad itself. The ad doesn’t take up the entire space between the first and second post. Around the ad it’s just white and I’d like to be the other color I posted before. Is that possible?
Jeremy, sure, there’s no reason you can’t go into the AdSense code block itself and set a specific background color, You can do that on the AdSense site itself, or you can just dig into the JavaScript block and set the value google_color_bg to whatever you want. On this page, for example, I use “google_color_bg = “ffffff”;” to get the white background.
Great little MOD. I’m curious though if I could, instead of creating white space behind the ad, make the background color (#d5cba1) be what is seen behind the ad. Possible?
Just to update, I had to play around with this.
Does this work for phpbb in phpnuke?
Does it take 48 hours for ads to appear?
Great tutorial Dave, it worked the first time. Thank you!
First Time, Perfect.
Great Tutorial Dave, Thanks a Million
Wow, thanks for making it so simple.
@Viperdriver2000: the background color of the Google ads are done in the actual adsense makeup on the Google page.
working fine…thanks 🙂
we can also change if ($i==”0″) to if ($i < $total_posts) to make the ad appear after every post.
Ok well I didn’t like how it looked so after a little tweaking of my own I got it to look like an actual post just minus a few things. So if you do want it to look like an actual post then follow the tutorial exactly but just use this code instead: http://img178.imageshack.us/img178/3631/codeoi3.png
I put the code onto an image so you could see the entire code since it’s a bit longer but I like it much more now cause it blends in with the forum and looks much better.
hi,
can someone tell me how i can change the background color of the field where is the google adsense in?
now its white and i will it have blue.
can someone help me?
——————————–
hi,
kann mir einer sagen wie ich die hintergrundfarbe änder?
im moment ist sie weiß ich würde sie aber gerne blau haben.
weiß das einer?
danke
thx
cu vip
Hey thanks for the code its works great. Currently tested it on the OR Forum @ http://www.brainhead.info. The site though is still under construction though. But thanks again. Really appreciate it.
hi.. i have truble with the code
$adblocktext =
Insert your Google AdSense Code Here
EOM;
i have to delete EOM? what is that? i delete the code but i get
Parse error: parse error, unexpected ‘=’ in /viewtopic.php on line 3
!!??? help pleaseª!
nice modification man. thanks for the help.
Wow! It worked perfectly for me. Thanks to the author and DAVE as well for bringing up this.
Thanks a lot for this. It was very easy to make. Thanks.
Works well. But in 800X600 resolution, I get horizontal bar because of the code.
Not working for me. Tried couple of times with different phpbb forums. Any ideas ?
if ($i==”0″) {
$adblock = $adblocktext;
} else {
$adblock = “”;
}Up near the beginning of the file, I defined the new variable $adblocktext thusly:
$adblocktext =
Insert your Google AdSense Code Here
EOM;
——————————————–
do it like this……
—————————————
if ($i==”0″) {
$adblock = $adblocktext =
EOM;
——————————–
works like a charm i cnt belive i got this code n got it workin after intense searchin of 2 months finally its here workin like a charm on phpbb 2.0.20
thanx alott u r the mannn!!
I did it! And this is the first time I hack into my phpBB code. Phew…Thank you!
Nice shortcut!
Where exactly do I put this? I mean what line range?
“Up near the beginning of the file, I defined the new…”
Great mod! I installed and am using it in
conjunction with phpadnews and it works
seamlessly. check it out if you want
http://www.rateyourbiz.net/forum
thank you very much
Ryan
Up near the beginning of the file, I defined the new variable $adblocktext thusly:
$adblocktext =
Insert your Google AdSense Code Here
EOM;
where should i put this part…..
I’m sorry but it didn’t work. I’ve checked the code a couple of times with no luck. Any ideas ?
This is great! It took me just a few minutes to install it on my phpBB forum at http://www.HURT911.org and at http://www.Lawyer-Advertising-Blog.com. It worked perfectly the second time (the first time was my fault). One note: I didn’t take out “Insert your Google AdSense Code Here” in viewtopic.php because I added // in front to make it a comment. That didn’t make it a comment, so I deleted it and it worked fine.
Thank you for this excellent sample code. We have been searching for something like this for some time now.
Thanks. I use this feature in my forum and waiting for good money.
Excellent, I can confirm that it works great on 2.0.20, If anyone is having problems, double check your code changes.
http://www.studio7wd.com
I have tried it several times and it does not work, any post i do now comes out blank, i am using phpbb version 2.0.19, please advise as to what i may be doing wrong
thanks man i wanted to find that for my site onlineludhiana.com
this works so brilliant! I got some other code before, but this one work without any harssle! thanks mate!
thank you for your advise, this code works perfectly!
Any demo?
thankyou very much… it worked without any hard work….. thanks
Just tried this on my new forum – works perfectly, and I don’t know anything about web code! Thanks so much.
Hello,
Thanks for that. How can I make it so that a 728×90 ad will be centered on a 800×600 resolution? Right now it causes horizonal scroll. Any ideas would be great.
Thanks.
Hi,
Thank you very much for this advice!
It took me about 45 minutes to figure out why it wasn�t working… I pasted the “{postrow.AD_BLOCK}” *below* “”…
Thats because my English is very poor and I frequently misunderstand “below” and “above”…
Thanks again,
Tiago Serafim