Please login or register.

Login with username, password and session length
Advanced search  


Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Adsense integration  (Read 4962 times)


  • 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:

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


  • 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.
function adsense($class = ''){$extraon=1;if ($extraon==1){
   $echo= '<div ';
   if ($class!=''){$echo.='class="'.$class.'"';}
if ($_SESSION[db('website').'Logged_In'] == token()) { // if logged in, show a placeholder
   $echo.='No Google
content here';   }
}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 »
Of all the things I have lost, it is my mind that I miss the most.


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

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