Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Adsense integration  (Read 4123 times)

paladin2

  • Newbie
  • *
  • Karma: 0
  • Posts: 10
Adsense integration
« on: April 30, 2007, 01:06:58 PM »

Hi there,

how can I modify the snews script to integrate google adsense into each article.

I'd like to include 1 adsense ad / article.

An example is shown here:

http://www.web-articles.info/e/a/title/The--Cost-of-Doing-Internet-Advertising-and-Business/

Thanks so much,
Robert
Logged
Read computers and technology  related articles. I used sNews to create my Max web design.

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Adsense integration
« Reply #1 on: April 30, 2007, 07:59:48 PM »

various ways you can do this, but you do need to be careful to ensure you don't breach adsense rules on your site.

The way I have done it means I have 1, 2 or 3 adblocks per page.
1 is installed in index.php.==> always shows.
1 is installed in snews before comments area.=> which means an article must be commentable for it to appear.
1 is installed after the block containing comments.=> which means an article needs to be commented before it appears.
 (ok, that is not optimum for adsense revenue, but so what ;) )

1) make a function in snews.php that outputs your adsense code.
-- I have it so that if I am logged in, no adsense is shown.
2) place function calls in relevant part of snews code.
-- to inject directly into an article automatically, suggest you look in the file_include() function, as this function handles the article text. You would probably make insertion based on a count of the </p> tags (say for eg, insert after the 4th occurence) , and insert the function call between the </p> and <p>;
-- try to avoid placing the adsense in the shortened article.

Here is the basic function I am using. See how you go getting it inserted were you want.
Quote
function adsense($class = ''){$extraon=1;if ($extraon==1){
   $echo= '<div ';
   if ($class!=''){$echo.='class="'.$class.'"';}
   $echo.='>';
if ($_SESSION[db('website').'Logged_In'] == token()) { // if logged in, show a placeholder
   $echo.='No Google
content here';   }
else{
$echo.='GOOGLE SCRIPT GOES HERE';
}$echo.='</div>';
}return $echo;}
$extraon allows me to switch this function on or off.
$class allows me to assign a class for styling purposes -- allows variable styling of the adblock
-- to call with a class, use adsense('CLASSNAME'); in your script.
« Last Edit: August 22, 2007, 12:43:15 AM by Phil Martin »
Logged
Of all the things I have lost, it is my mind that I miss the most.

paladin2

  • Newbie
  • *
  • Karma: 0
  • Posts: 10
Adsense integration
« Reply #2 on: June 24, 2007, 12:31:35 PM »

thanks a lot, that helped.
Logged
Read computers and technology  related articles. I used sNews to create my Max web design.