Need help with a small piece of PHP code (for green rep)

Discussion in 'PHP' started by BuenosAires, Apr 27, 2007.

  1. #1
    Please go easy to me, I know little or nothing about PHP.

    I am trying to insert some code in my Wordpress single post template so that my adsense does not appear on a couple of posts, but still on the rest.

    This is what I have tried (remember, I know nothing about PHP!)...

    <?php if( $URI == 'this-is-a-url-string'
    || $URI == 'this-is-also-a-url-string' ) {
    '
    ';
    } else {
    'HERE IS MY FULL ADSENSE CODE';
    }?>​

    But it isn't working.

    What do I need to change for this to work?

    Any help will get green rep :)
     
    BuenosAires, Apr 27, 2007 IP
  2. Martindale

    Martindale Well-Known Member

    Messages:
    440
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Are you getting any errors?

    <?php if(!($URI == 'this-is-a-url-string' || $URI == 'this-is-also-a-url-string')) { ?>
    
    adsense code here.
    
    <?php
    }?>
    Code (markup):
    That should work much better for you. :)
     
    Martindale, Apr 27, 2007 IP
    BuenosAires likes this.
  3. adamjthompson

    adamjthompson Well-Known Member

    Messages:
    1,242
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    125
    #3
    Is the variable URI defined elsewhere in the script? If not, try using
    $_SERVER['REQUEST_URI']
    PHP:
     
    adamjthompson, Apr 27, 2007 IP
    BuenosAires likes this.
  4. brealmz

    brealmz Well-Known Member

    Messages:
    335
    Likes Received:
    24
    Best Answers:
    3
    Trophy Points:
    138
    #4
    you want adsense not to appear on some pages? am i correct?
    if yes..
    store $uri in a array instead.

    !note: if not working echo $_SERVER['REQUEST_URI']so you will have an idea why
     
    brealmz, Apr 27, 2007 IP
    BuenosAires likes this.