Wordpress: Showing ads conditional on specific pages?

Discussion in 'WordPress' started by AbdullahFarouk, Mar 23, 2007.

  1. #1
    I have been pulling my hair out trying to show adsense ads conditional on certain pages with no luck. One approach to show Adsense ads conditional on specific Pages that seems logical, and avoids using Echo, but doesnt work, is to concatenate the Pages you don't want the code to show.

    But I can't get this to work either:

    <?php if(!is_page(181) || !is_page(182) || !is_page(183) || !is_page(184) || !is_page(185) || !is_page(186) || !is_page(187)): ?>
    <!-- Google Code -->
    <script type="text/javascript"><!--
    google_ad_client = "";
    google_ad_width = 336;
    google_ad_height = 280;
    google_ad_format = "336x280_as";
    google_ad_type = "text";
    google_ad_channel = "";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "6B8F16";
    google_color_text = "000000";
    google_color_url = "000000";
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <?php endif; ?>

    What I am saying above is "if we aren't on this page...do this" Any ideas where I am messing up?
     
    AbdullahFarouk, Mar 23, 2007 IP
  2. casperl

    casperl Peon

    Messages:
    1,560
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I guess you can do this with openads in a more flexible way. Try googling it. I did not use it but if i decide to do what you said, i would like to try that one first. Actually you can use it for all of your site with one installation!
     
    casperl, Mar 24, 2007 IP
  3. AbdullahFarouk

    AbdullahFarouk Peon

    Messages:
    96
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I resolved this and post it so it might be of use to someone else. The expression for "not", "!" should be stated once before the iteration to test each multiple conditional begins. The whole problem with the Wordpress conditional "is_page" tag is that it cannot test multiple pages at once, eg: is_page(183,184,185,etc), so we have to find a way to get around this.

    This works perfectly, when I put it directly into the template:

    <?php if (!( is_page(181) || is_page(182) || is_page(183) || is_page(184) || is_page(185) || is_page(186) || is_page(187) )) { ?>

    <script type="text/javascript"><!--
    google_ad_client = "";
    google_ad_width = 336;
    google_ad_height = 280;
    google_ad_format = "336x280_as";
    google_ad_type = "text";
    google_ad_channel = "";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "6B8F16";
    google_color_text = "000000";
    google_color_url = "000000";
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <?php } ?>

    What the above says is "if we are NOT on page 182, 183, etc...do this.."

    This is a good idea if you don't want to use a plugin, and dont want to show ads on useless pages, since IMO, getting rid of Google ads on low paying pages seems to improve overall earnings.

    I will check that plugin tho :)
     
    AbdullahFarouk, Mar 24, 2007 IP