1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

If author=XXX, show adsense code 2, otherwise, code 1

Discussion in 'PHP' started by Boris4ka, Dec 8, 2009.

  1. #1
    That's basically what I need to accomplish. This is for wordpress. I don't want to use a plugin because there is none which does exactly what I want. I have a precise template that I made and want to keep as is, and plugins only let me insert ads on the sidebar and inside posts.

    So basically I need to write some PHP that will show an adsense code for a specific author, and another adsense code for everyone else.

    So something like:

    If author = tom, adsense2
    else
    adsense1

    You get what I'm trying to do? Please help, I know this should be simple to do, it's just going to be outputting a different ECHO depending on the author var, right?

    Thanks
     
    Boris4ka, Dec 8, 2009 IP
  2. aquilax

    aquilax Member

    Messages:
    126
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #2
    You can get the author with this function
    http://codex.wordpress.org/Function_Reference/get_the_author
    Code (markup):
    Get the author check it's name then show the code you want.
     
    aquilax, Dec 8, 2009 IP
  3. Boris4ka

    Boris4ka Well-Known Member

    Messages:
    172
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #3
    But that has to be used within the Loop. My ads are outside the Loop.
     
    Boris4ka, Dec 8, 2009 IP
  4. aquilax

    aquilax Member

    Messages:
    126
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #4
    Then set the variable in the loop and use it outside the loop. I guess you're checking for single post's author only.
     
    aquilax, Dec 8, 2009 IP
  5. Boris4ka

    Boris4ka Well-Known Member

    Messages:
    172
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Unfortunately I don't know enough about PHP to do this on my own. Can you please start me off with some basic code? I can understand and edit it, I just don't have the knowledge to write it from scratch :(
     
    Boris4ka, Dec 8, 2009 IP
  6. aquilax

    aquilax Member

    Messages:
    126
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #6
    Last edited: Dec 9, 2009
    aquilax, Dec 9, 2009 IP
  7. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #7
    
    if ($author == "tom")
    {
        echo "adsense2";
    }
    else
    {
        echo "adsense1";
    }
    
    PHP:
     
    Kaizoku, Dec 9, 2009 IP