News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Adsense issues - Getting It Off Multiple Site Pages

Started by Dio, July 19, 2005, 06:48:41 PM

Previous topic - Next topic

Dio

Help For A PHP Luddite reuired, to stay inside the Adsense TOS.

I've got thus far. Its fair to say I know very little on PHP - well nothing in fact.

I've dredged through old threads where I found adding this would help to keep the adsense code off the Admin Pages and the Login Page:



if (!isset($context['admin_areas']) && $context['sub_template'] != 'login')
echo '<div align="center" class="tborder">
<script type="text/javascript"><!--
google_ad_client = "pub-0691188711472327";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="8678466755";
google_color_border = "FFCCFF";
google_color_bg = "FFCCFF";
google_color_link = "333333";
google_color_url = "333333";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>';



Which works a treat. I want to expand that somewhat so it doesn't appear on post pages and any member profile pages. I'm guessing its something to do with this bit of the code.



$context['sub_template'] != 'login')



And was wondering what the syntax would be to make that for multiple site bits like post - profile etc. Any help appreciated, this is my first ever forum, and its been a breeze so far!
Crazy Frog Fans Forum [nofollow] | Cheesy Movies [nofollow] | Chav Mum [nofollow] | Viral Auctions [nofollow]

That's Welsh Dai-O, Not Ronnie James Day-o

[Unknown]

!in_array($context['sub_template'], array('x', 'y', 'z'))

-[Unknown]

Dio

Can I just confirm, instead of :

if (!isset($context['admin_areas']) && $context['sub_template'] != 'login')

I use


if (!isset($context['admin_areas']) &&  !in_array($context['sub_template'], array('x', 'y', 'z')))


in which case, x y z - is there a list of sub template names I can use there?

I already have 'login' - would it be like 'profile', 'post' ?

Thanks for the help so far
Crazy Frog Fans Forum [nofollow] | Cheesy Movies [nofollow] | Chav Mum [nofollow] | Viral Auctions [nofollow]

That's Welsh Dai-O, Not Ronnie James Day-o

[Unknown]

Yes.  There's no list on hand, but if you tell me what areas you want removed, I can tell you what you can use to remove them.

-[Unknown]

Dio

Awsome - basically, any user profile pages, personal message pages and the post a reply/topic page. I got admin and login covered. ;)
Crazy Frog Fans Forum [nofollow] | Cheesy Movies [nofollow] | Chav Mum [nofollow] | Viral Auctions [nofollow]

That's Welsh Dai-O, Not Ronnie James Day-o

[Unknown]

!in_array('profile', $context['template_layers']) && !isset($context['post_errors'])

Would be the simplest ways to check for those.

-[Unknown]

Dio

Yeah - that's got it suckered. I can stay with in the Adsesne TOS now. Sending a virtual pint or three your way now. :D
Crazy Frog Fans Forum [nofollow] | Cheesy Movies [nofollow] | Chav Mum [nofollow] | Viral Auctions [nofollow]

That's Welsh Dai-O, Not Ronnie James Day-o

icfsindia

Thanks for all the postings of  yours.

What I understand,

Quoteif (!isset($context['admin_areas']) && $context['sub_template'] != 'login')

This will disable google adsense code from functioning in admin pages and login page.
The code is pasted after this statement with a echo' command.


Quote!in_array('profile', $context['template_layers']) &&
!isset($context['post_errors'])

This will  enable you to collect the various sub_template names like login for
login template etc.

But how and where to use this and how to obtain the list of templates.  I did
not understand..


Quoteif (!isset($context['admin_areas']) &&  !in_array($context['sub_template'],
array('x', 'y', 'z')))

This is the code that is to be used to disable the code from more than one
pages, where x, y and z are to be replaced with the relevant names of the
templates related to the pages in which the ads are to be disabled.

Please help me out

Regards
Ratnakar

Gargoyle

Could you please post the entire code for this check that you and [unknown] have done such a good job at figuring for the rest of us to use Dio ?

I have been struggling with this as well and your code would make my life a ton easier.

icfsindia



   // Show the menu here, according to the menu sub template.
   template_menu();

   echo '
         </td>
      </tr>';

// Show ads only in non-mod/admin areas

if (!isset($context['admin_areas']) && $context['sub_template'] != 'login' )
~~~~~Actual content switched off/on by the if() condition~~~~~

   echo '
<tr><td align="center" colspan="2" height="100" valign="bottom" bgcolor="#d0d0d0">

<script type="text/javascript">
google_ad_client = "pub-XXXXXXXXXXX";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_channel ="XXXXXXX";
google_color_border = "d0d0d0";
google_color_bg = "FFFFFF";
google_color_link = "000080";
google_color_url = "005177";
google_color_text = "000000";
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js [nofollow]"> </script>

</td></tr>';
~~~~~End Actual content switched off/on by the if() condition~~~~~

   // Show a random news item? (or you could pick one from news_lines...)
   if (!empty($settings['enable_news']))

Dio

That's about it - but you can use a div align and a set class as well if you like, to add the content in the style of the block the ad appears in.

However, something is going wrong somewhere for me - I'm now getting the code showing in admin areas and login pages, but not in PM and those areas. I wish I knew PHP :(
Crazy Frog Fans Forum [nofollow] | Cheesy Movies [nofollow] | Chav Mum [nofollow] | Viral Auctions [nofollow]

That's Welsh Dai-O, Not Ronnie James Day-o

Gargoyle

Very good! I am off to a great start now!

I am still confused by this one though....
!in_array('profile', $context['template_layers']) && !isset($context['post_errors'])

I tried to implement it but I get errors when I do. I must be missing something.

[Unknown]

Quote from: Gargoyle on August 07, 2005, 12:46:52 PM
Very good! I am off to a great start now!

I am still confused by this one though....
!in_array('profile', $context['template_layers']) && !isset($context['post_errors'])

I tried to implement it but I get errors when I do. I must be missing something.

Instead of:

if (!isset($context['admin_areas']) && $context['sub_template'] != 'login')

Use:

if (!isset($context['admin_areas']) && $context['sub_template'] != 'login' && !in_array('profile', $context['template_layers']) && !isset($context['post_errors']))

-[Unknown]

Gargoyle


Dio

I figured out why it had stopped working for me, and all is fine now (using old verison of the page).  :-X

Except for one last place that I'd like to remove it from. The register pages. Any ideas how? Is there one final switch to add to the above code or is it just causing more nightmares. :)

Then finally I can relax about having adsense on the forum. :)
Crazy Frog Fans Forum [nofollow] | Cheesy Movies [nofollow] | Chav Mum [nofollow] | Viral Auctions [nofollow]

That's Welsh Dai-O, Not Ronnie James Day-o

[Unknown]

For the registration page:

isset($context['require_agreement'])

There are other methods, but that's probably going to stand up best to upgrades.

-[Unknown]

Dio

Thanks once again. I am finally sorted this time... I promise. As far as I can see I'm now totally within the AdSense TOS. :)

I'm sure this info will be of use to quite a few people like myself - thanks for taking the time to help out a newb. :)
Crazy Frog Fans Forum [nofollow] | Cheesy Movies [nofollow] | Chav Mum [nofollow] | Viral Auctions [nofollow]

That's Welsh Dai-O, Not Ronnie James Day-o

icfsindia

Quoteisset($context['require_agreement'])

The above code removed the ads from the search page.

A summary of what I understood.

Quoteif
(!isset($context['admin_areas'])
          --> Specifies all pages accessible only to the admin
$context['sub_template'] != 'login'
          --> Specifies login page
!in_array('profile', $context['template_layers'])
          --> Specifies profile page
!isset($context['post_errors'])
          --> Specifies postage error page
isset($context['require_agreement']))
          --> Specifies search page

What is the code for removing the ads from agreement page.  I think that is the only area that is left to be handled.

I did not read through the google TOS clearly.  Is it a requirement that we eliminate the code from the search page.


icfsindia

Quoteif (!isset($context['admin_areas']) && $context['sub_template'] != 'login' && !in_array('profile', $context['template_layers']) && !isset($context['post_errors']) && isset($context['require_agreement']))

Hi all the code seems to have removed the ads from the calendar page also.

I want the ads to appear on the calendar page.  Is it in any way a violation of googles TOS to make ads appear on the calendar page!!!

Is my analysis that
Quote!in_array('profile', $context['template_layers'])
removes ads from calender, etc correct!!!

icfsindia

#19
Google AdSense Program Policies
Ad Placement

  • Up to three ad units may be displayed on each Web site page.
  • A maximum of two Google AdSense for search boxes may be placed on a page.
  • A single link unit may be placed on each Web site page, in addition to the ad units and search boxes specified above. Link units are considered to be 'Google ads' for purposes of these program policies.
  • No Google ad may be placed on any non-content-based pages. This includes error, login, registration, "thank you" or welcome pages.
  • No Google ad or Google search box may be displayed on any domain parking websites, pop-ups, pop-unders, or in any email.
  • No Google ad may be placed on pages published specifically for the purpose of showing ads, whether or not the page content is relevant.
  • Elements on a page must not obscure any portion of the ads, and the ad colors must be such that any ad elements, including text and URL, are visible.
  • Clicks on Google ads must not result in a new browser window being launched.
Google AdSenseTM Online Standard Terms and Conditions


(v) display any Ad(s) or Link(s) on any error page, on any registration or "thank you" page (e.g., a page that thanks a user after he/she has registered with the applicable Web site), on any chat page, in any email, or on any Web page or any Web site that contains any pornographic, hate-related, violent, or illegal content;

Conclusions

Do not display ads on login, error, registration, thankyou pages.
Where was the restriction relating to displaying ads on admin pages.
however since clicking on ads by the web site publisher himself would amount to fraud, may be it would be convenient to eliminate ads appearing on admin pages.

icfsindia

Quoteif (!isset($context['admin_areas']) && $context['sub_template'] != 'login' && !in_array('profile', $context['template_layers']) && !isset($context['post_errors']) && isset($context['require_agreement']))

this removed ads from all my pages!!!!!!!!!!

icfsindia

Quote
if (!isset($context['admin_areas'])
&& $context['sub_template'] != 'login'
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement']))

If       Context is not admin_areas
and   sub_template is not 'login'
and   template_layers is not 'profile'
and   Context is not post_errors
and   Context is not require_agreement

Then do the code below or move away to the next statement.

This worked fine for me for the login, admin, agreement, post and post error pages.

I think that much is what we want

Thank you all for sharing your knowledge.


If someone finds this not functioning, please post the message, since i can also modify my code to enable it to function properly.

regards
ratnakar




Dio

That's it - just to expand it slightly for people



// Show the menu here, according to the menu sub template.
template_menu();

echo '
</div>';

if (!isset($context['admin_areas']) && $context['sub_template'] != 'login'
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement']))

echo 'html / adsense code here';



As for it not being in Admin areas, they would be termed as non-content. Now, The only thing I'm missing now, after I believed I had it all... Is to get it off the search pages. :D
Crazy Frog Fans Forum [nofollow] | Cheesy Movies [nofollow] | Chav Mum [nofollow] | Viral Auctions [nofollow]

That's Welsh Dai-O, Not Ronnie James Day-o

[Unknown]

!isset($context['search_params'])

Is that what you want?

-[Unknown]

Dio

That didn't work for me, however, it made me go and look in the search template and try this:

!isset($context['simple_search'])

which did work - do you foresee any problem with that? If I knew anything about PHP I could maybe see the potential for making a mod to help with this stuff - tick what pages you want it on etc. I wouldn't know where to start though :(

Thanks again for the help!
Crazy Frog Fans Forum [nofollow] | Cheesy Movies [nofollow] | Chav Mum [nofollow] | Viral Auctions [nofollow]

That's Welsh Dai-O, Not Ronnie James Day-o

[Unknown]

I guess the only danger is that that may not show in search administration, where you don't want it to show anyway :P.

-[Unknown]

Dio

Crazy Frog Fans Forum [nofollow] | Cheesy Movies [nofollow] | Chav Mum [nofollow] | Viral Auctions [nofollow]

That's Welsh Dai-O, Not Ronnie James Day-o

Gargoyle

Dio could you please post your finished code. Thank-you

icfsindia

Quoteif (!isset($context['admin_areas'])
&& $context['sub_template'] != 'login'
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement'])
&& !isset($context['simple_search']))

If       Context is not admin_areas
and   sub_template is not 'login'
and   template_layers is not 'profile'
and   Context is not post_errors
and   Context is not require_agreement
and   Context is not search page     [Only search form and not results]


bjp

It's working, but this gives mes errors

8: Undefined index: sub_template
Fichier: /var/www/html/site/smf/Themes/default/index.template.php
Ligne: 274

The line 274 is : && $context['sub_template'] != 'login'


with this code :

      // Show the menu here, according to the menu sub template.
      template_menu();

   echo '
   </div>';
if (!isset($context['admin_areas'])
&& $context['sub_template'] != 'login'
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement']))

echo '
            <br /><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-1232486685154xxx";
google_alternate_color = "f9f9f9";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="0560275031";
google_color_border = "f9f9f9";
google_color_bg = "f9f9f9";
google_color_link = "660000";
google_color_url = "000000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
            </div></td>
  </tr>
</table>';

bjp

And is it possible to deseable adsense on a private section ?

[Unknown]

Instead of:

&& $context['sub_template'] != 'login'

Use:

&& isset($context['sub_template']) && $context['sub_template'] != 'login'

Private section as in a certain board?  Add:

&& (empty($context['current_board']) || $context['current_board'] != ###)

Where ### is the board's id.

-[Unknown]

bjp


-Scott

After changing this && $context['sub_template'] != 'login' (which was causing an error in the log) to this && isset($context['sub_template']) && $context['sub_template'] != 'login' it won't show on any page  now???



-Scott

[Unknown]

Sorry, you want:

&& (!isset($context['sub_template']) || $context['sub_template'] != 'login')

Then.

-[Unknown]

bjp

I use this code not to display adsense on some part of my board, i'ts ok

if (!isset($context['admin_areas'])
&& (!isset($context['sub_template']) || $context['sub_template'] != 'login')
&& (empty($context['current_board']) || $context['current_board'] != 4.0)
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement'])
&& !isset($context['simple_search']))

I do not want to display adsense on boardindex. How to do this ?

Sledgemoto

This should be a sticky. For top and bottom inclusion for 1.1 RC 2


Quote// Show the menu here, according to the menu sub template.
   template_menu();


   // The main content should go here.
   echo '
   <div id="bodyarea" style="padding: 1ex 0px 2ex 0px;">';
   if (!isset($context['admin_areas'])
&& (!isset($context['sub_template']) || $context['sub_template'] != 'login')
&& (empty($context['current_board']) || $context['current_board'] != 4.0)
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement'])
&& !isset($context['simple_search']))

echo '
            <br /><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-1053276976865774";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text";
google_ad_channel ="9826615372";
google_color_border = "000000";
google_color_bg = "F0F0F0";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js [nofollow]">
</script>
            </div></td>
  </tr>
</table>';
}

function template_main_below()
{
   global $context, $settings, $options, $scripturl, $txt;

    echo '
   </div>';
if (!isset($context['admin_areas'])
&& (!isset($context['sub_template']) || $context['sub_template'] != 'login')
&& (empty($context['current_board']) || $context['current_board'] != 4.0)
&& !in_array('profile', $context['template_layers'])
&& !isset($context['post_errors'])
&& !isset($context['require_agreement'])
&& !isset($context['simple_search']))

echo '
            <br /><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-1053276976865774";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text";
google_ad_channel ="9826615372";
google_color_border = "000000";
google_color_bg = "F0F0F0";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js [nofollow]">
</script>
            </div></td>
  </tr>
</table>';
   

   // Show the "Powered by" and "Valid" logos, as well as the copyright. Remember, the copyright must be somewhere!
   echo '



as seen here http://talkingautosurfs.com [nofollow]

SteveWh

#37
Sorry to resurrect such an old topic, but it's exactly what my question is about.

Instead of specifying a long list of pages where AdSense should not be put, I made a very short list of the pages were I do want it:

Only Board indexes and Topic display pages.

After examining the code, here's the test I came up with:

[Edited: Added 2nd line to eliminate ads from the Modify Message, New Topic, and any error page.]

if ((isset($context['current_topic']) || isset($context['current_board']))
    && !isset($context['message']) && !isset($context['post_errors']))...

It does seem to be accomplishing what it's supposed to, but is there anything about it that is bad?

I'm trying to add the main forum index page to the list without adding anything else, but haven't found a way yet.

Advertisement: