
phpBB trick for including Google AdSense between articles?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> 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>
and it worked just fine. Contributor Greg Bulmash has lots of cool Web sites, but invites readers to pop over to his fun baby clothes site. He says he could use the sales. :-)
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon
Categorized:
CGI Scripts and Web Site Programming
(Article 4062)
Tagged: Previous: Gmail: can't create message labels? Next: How to create new screen names on AOL (America Online)? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader. 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, Hello, Thanks for that. How can I make it so that a 728x90 ad will be centered on a 800x600 resolution? Right now it causes horizonal scroll. Any ideas would be great. Thanks. Posted by: Patrick at August 16, 2005 11:18 PMJust tried this on my new forum - works perfectly, and I don't know anything about web code! Thanks so much. Posted by: Sophie at November 29, 2005 3:16 PMthankyou very much... it worked without any hard work..... thanks Posted by: Abdullah at January 27, 2006 3:41 PMAny demo? Posted by: nicepuppy at February 6, 2006 7:35 PMthank you for your advise, this code works perfectly! Posted by: China Guide at February 7, 2006 4:20 PMthis works so brilliant! I got some other code before, but this one work without any harssle! thanks mate! Posted by: Oneandhalf Web Server at February 11, 2006 10:59 AMthanks man i wanted to find that for my site onlineludhiana.com Posted by: sarvpriya at March 15, 2006 9:05 AMI 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 Posted by: ravs at April 11, 2006 8:33 AMExcellent, I can confirm that it works great on 2.0.20, If anyone is having problems, double check your code changes. www.studio7wd.com Posted by: Studio 7 at April 24, 2006 2:51 AMThanks. I use this feature in my forum and waiting for good money. Posted by: aurumgames at May 2, 2006 2:05 PMThank you for this excellent sample code. We have been searching for something like this for some time now. Posted by: MoJeepin.com at May 17, 2006 1:29 PMThis is great! It took me just a few minutes to install it on my phpBB forum at www.HURT911.org and at 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. Posted by: Philip Franckel at June 24, 2006 10:11 PMI'm sorry but it didn't work. I've checked the code a couple of times with no luck. Any ideas ? Posted by: MD at July 10, 2006 4:56 PMUp near the beginning of the file, I defined the new variable $adblocktext thusly: $adblocktext =
where should i put this part..... Posted by: vj at July 16, 2006 5:22 AMGreat mod! I installed and am using it in thank you very much Ryan Posted by: Ryan at July 17, 2006 1:48 PMWhere exactly do I put this? I mean what line range? "Up near the beginning of the file, I defined the new..." Posted by: Tom Tomyt at July 19, 2006 8:09 PMNice shortcut! Posted by: Andrew at July 23, 2006 3:54 AMI did it! And this is the first time I hack into my phpBB code. Phew...Thank you! Posted by: lilian at July 25, 2006 10:55 AMif ($i=="0") { $adblocktext = EOM;
--------------------------------------- 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!! Posted by: rafay at August 6, 2006 9:35 PMNot working for me. Tried couple of times with different phpbb forums. Any ideas ? Posted by: Dat at August 27, 2006 1:03 PMWorks well. But in 800X600 resolution, I get horizontal bar because of the code. Posted by: Anand at August 29, 2006 9:18 AMThanks a lot for this. It was very easy to make. Thanks. Posted by: Siyah at August 29, 2006 7:35 PMWow! It worked perfectly for me. Thanks to the author and DAVE as well for bringing up this. Posted by: Saurabh at September 16, 2006 4:07 AMnice modification man. thanks for the help. Posted by: ludhiana at September 16, 2006 12:52 PMhi.. i have truble with the code $adblocktext = 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ª! Hey thanks for the code its works great. Currently tested it on the OR Forum @ www.brainhead.info. The site though is still under construction though. But thanks again. Really appreciate it. Posted by: OR Forum at September 27, 2006 1:34 PMhi, now its white and i will it have blue. can someone help me? -------------------------------- hi, weiß das einer? danke thx cu vip Posted by: Viperdriver2000 at October 12, 2006 2:48 PMOk 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. Posted by: eyeinthesky43 at December 4, 2006 9:29 PMworking fine...thanks :) we can also change if ($i=="0") to if ($i < $total_posts) to make the ad appear after every post. Posted by: Lovedeep Wadhwa at December 30, 2006 3:56 AMWow, 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. Posted by: Brian at December 30, 2006 4:30 PMFirst Time, Perfect. Great Tutorial Dave, Thanks a Million Posted by: Keith Donegan at January 1, 2007 11:09 PMGreat tutorial Dave, it worked the first time. Thank you! Posted by: Gentry Sherrill at January 24, 2007 5:29 PMDoes it take 48 hours for ads to appear? Posted by: b at February 15, 2007 1:59 AMDoes this work for phpbb in phpnuke? Posted by: Abe at February 19, 2007 3:20 PMJust to update, I had to play around with this. Posted by: Abe at February 19, 2007 3:55 PMGreat 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? Posted by: Jeremy at February 27, 2007 9:58 AMJeremy, 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. Posted by: Dave Taylor at February 27, 2007 10:42 AMThanks 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? Posted by: Jeremy at February 27, 2007 1:55 PMI 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%"> and that should hopefully accomplish what you seek! Posted by: Dave Taylor at February 27, 2007 2:31 PMIf 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 Posted by: Fish-Guy at February 28, 2007 9:14 AMThanks for this code - it works perfectly on my site at www.canadahealthinfo.ca/forum. Posted by: Jack at February 28, 2007 10:22 PMvery nice! Once I opened the files it took about 5 minutes to change them and then done. Great step by step guide. Posted by: Jacob at March 14, 2007 11:16 PMit worked for me too ! very nice ! Posted by: Emil at March 20, 2007 12:03 AMDoesnt work for me. Can anyone pls help me with details. Posted by: abhi at March 24, 2007 11:30 PMI am using MorpheusXDarkBlue as my style. I couldn't find the end post row line in the file. 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? Posted by: david at April 8, 2007 9:09 PMThanks for this code. And yes, you can insert Javascript. I tried the following...$adblocktext = <<<EOM <tr><td class="spaceRow" colspan="2" height="1"><img How to use javascript i dont understand.I am begener. Posted by: Amko at April 13, 2007 3:39 AMOkay, 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 Posted by: Joseph at April 13, 2007 9:11 AMWhat do you mean by "Up near the beginning of the file, I defined the new variable $adblocktext thusly:" Where the hell is that!!! Posted by: Cathal at May 2, 2007 3:27 AMMany Thanks! This has just saved me a lot of head scratching on a current project! Chris Posted by: Chris at May 21, 2007 1:14 PMgood work on this article, but I have a different question, how would I do this on phpbb3? Posted by: Erick at May 30, 2007 1:48 PMCool, it worked for me too ! Thanks! ! Posted by: Mike at June 12, 2007 3:23 PMhey thank you very much for that Ive been looking all over for that Posted by: jessica at July 5, 2007 1:14 PMThaanks...Great Help ...You made my work easier Regards VK Posted by: vk at August 16, 2007 11:23 AMhi Is this script a wind up?? Can anyone show me a forum where it works as all the ones mentioned above dont have it working!!!! Posted by: toolpusher at August 27, 2007 9:33 PMOOPS sorry found it working on some sites but spent two days on mine just about giving up!!! Posted by: Toolpusher at August 27, 2007 10:18 PMYah ask Dave taylor, but where is dave taylor when many people ask this sentence ? ---------------------------- "Up near the beginning of the file, I defined the new..." may be the owner must change "ask Dave Taylor" to "don't ask dave taylor" Posted by: sys at August 28, 2007 3:20 AMEasy there, sys. With over 100 comments a day added to the site, I can't field every question from every user. Further, I admit, I am pretty clueless about PHP and it was a friend of mine who helped out with this one. If you want to be helpful, please come back once you've figured this out and post your solution for others to read and learn from. That'd be a community service. :-) Posted by: Dave Taylor at August 28, 2007 7:20 AMthanks for your information, it really helped me in instaling as i liked google Posted by: mark at September 14, 2007 7:03 PMThis worked brilliantly! Thank you! Posted by: George at September 21, 2007 7:08 AMGreat tip worked a charm www.scripts2go.co.uk Posted by: David at October 9, 2007 6:57 AMGREAT GREAT GREAT! It works perfect on last 2.0.22 version! It must works! Can`t believe that was so simple. open this tpl file with wordpad and do this {postrow.AD_BLOCK}
Worked like a charm! You are the best. Thank you Posted by: Tim at November 16, 2007 12:03 PMhow to integrate adsense with andromeda(mp3 server) Posted by: jeswinder singh at December 5, 2007 2:01 AMVery Nice!!! This code work perfect in 2.0.22 !!! Works great, only one problem it stretches the whole of the 2nd column to the same width as the ad in IE only? I think that my above problem might be due to a bug in IE i hear, is there any other workaround other than using colspan? i did try nesting tables but it just messes up my forum, can anyone help. Posted by: wd_2k6 at December 15, 2007 6:41 PMhey guys ,this is so amazing and simply mode :)) thanks a lot ...but I did mistake in a first part , because of the term"up to next" such as use here insert your adsense code Posted by: cviky na břicho at February 25, 2008 9:42 AMCouldn't find the right place he is talking about. I also have phpBB3 im kind of lost here.:-( Posted by: Pramod at March 6, 2008 4:22 PMThanks so much, finally i could find a mod that worked on my phpbb. Posted by: medical at March 11, 2008 5:20 PMThis is just great, absolutely fabulous! Posted by: Jude at March 13, 2008 1:21 AMMr Taylor does any one how too work it on phpbb3??? Posted by: RAJA YALAMANCHILI at July 30, 2008 9:35 PM"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"
Thanks !!! thnx Posted by: Mahendra at January 27, 2009 9:54 AMthanks man , hope it works.... Posted by: suganindia at August 12, 2009 8:16 AMThanks very much - I am going to add this to my support forum. Posted by: Jordan at January 6, 2010 2:14 PMI have something to say, now that you mention it, but ...
I do have a comment, now that you mention it!
|
![]()
Search
Find just the answers you seek from among our 2300+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Industry News and Trade Shows Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Book Links
|