Home Articles CV / Résumé Downloads Photo Gallery Web LinksJanuary 07 2009 11:19:41
How to add Google Adsense to Articles
Open readarticle.php in the root folder of your php fusion installation, around line 30-ish you will see the following code,
$article = stripslashes($data['article_article']);
$article = explode("<!--PAGEBREAK--!>", $article);
$pagecount = count($article);
$article_subject = stripslashes($data['article_subject']);
$article_info = array(
"article_id" => $data['article_id'],
"user_id" => $data['user_id'],
"user_name" => $data['user_name'],
"article_date" => $data['article_datestamp'],
"article_breaks" => $data['article_breaks'],
"article_comments" => dbcount("(comment_id)", "comments", "comment_type='A' AND comment_item_id='".$data['article_id']."'"),
"article_reads" => $data['article_reads'],
"article_allow_comments" => $data['article_allow_comments']
);
render_article($article_subject, $article[$rowstart], $article_info);

we are gonna modify that so that we can add the block ad before and the rectangular ad at the bottom.
$article_pre = "<table border='0' cellspacing='5' cellpadding='2' align='left'><tr><td><script type=\"text/javascript\"><!--
google_ad_client = \"PLACE YOUR AD_CLIENT # HERE\";
google_ad_width = 250;
google_ad_height = 250;
google_ad_format = \"250x250_as\";
google_ad_type = \"text\";
google_ad_channel =\"\";
google_color_border = \"F7F7F7\";
google_color_bg = \"F7F7F7\";
google_color_link = \"0000FF\";
google_color_text = \"000000\";
google_color_url = \"008000\";
//--></script>
<script type=\"text/javascript\" xsrc=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script></td></tr></table>";
$article = stripslashes($data['article_article']);
$article = explode("<!--PAGEBREAK--!>", $article);
$pagecount = count($article);
$article_post = "<center><script type=\"text/javascript\"><!--
google_ad_client = \"
PLACE YOUR AD_CLIENT # HERE\";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = \"468x60_as\";
google_ad_type = \"image\";
google_ad_channel =\"\";
google_color_border = \"F7F7F7\";
google_color_bg = \"F7F7F7\";
google_color_link = \"0000FF\";
google_color_text = \"000000\";
google_color_url = \"008000\";
//--></script>
<script type=\"text/javascript\" xsrc=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script></center>";
$article_subject = stripslashes($data['article_subject']);
$article_info = array(
"article_id" => $data['article_id'],
"user_id" => $data['user_id'],
"user_name" => $data['user_name'],
"article_date" => $data['article_datestamp'],
"article_breaks" => $data['article_breaks'],
"article_comments" => dbcount("(comment_id)", "comments", "comment_type='A' AND comment_item_id='".$data['article_id']."'"),
"article_reads" => $data['article_reads'],
"article_allow_comments" => $data['article_allow_comments']
);
render_article($article_subject, $article_pre.$article[$rowstart].$article_post, $article_info);

As you can now tell, the $article_pre takes care of the block ad (you may change the adsense code to which ever type/format of add you want placed there) and the $article_post is for the rectangular ad at the end (again you may change the adsense code to reflect what type/format ad you want placed there).

And that's it, simple as that! Now, no matter what theme you take the adsense will always be there, but you will have to change the colour codes to reflect the new colour scheme. I haven't read/found out how to get it to take the colours from the CSS scheme yet, working on it.

Thanks for reading through,
Adnan.
Post Comment
Name:



Smile Wink Frown Sad Shock Pinch Cool Grin Angry Roll Uh-oh! Thumbs Down Sleep Laughing Dead Ouch Mad Tongue Clap Hug Geek Confused Thumbs Up Shy Laugh Asking Fingers Crossed Yahoo
4 + 3=
Disable smileys in this comment

Comments
Ahmed on February 15 2007 16:35:10
Ooh sorry Adnan,

I did it well many thanks. the second thing how to add to the News
Adnan on February 14 2007 14:23:50
Wat's giving you trouble? Can't find where to add the google adsense code?
ahmed on February 13 2007 19:53:20
Hi Adnan I did what you said but its not working,
Can you explain please more
K@iTO on December 09 2006 08:55:54
xsrc=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\




Ok fund it :D
K@iTO on December 09 2006 06:03:15
Nice but... I have problem with it... Normaly all Your articles are so good that every thing is ok. but now it isn't.

Check my Web site. www.dupczybiedy.ovh.org

I have add all as You have (with google change ID)
All should work but...

All night working on it but... still nothing.
Ratings
Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.

This site is optimized for viewing with Firefox!
All articles, pictures, and any other material obtained from this site is Copyright © 2007, and may not be reproduced without permission from the author.
Link Exchange - Directory - Windows Hosting