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.

Wordpress code to show ad in sidebar on homepage only

Discussion in 'Scripts' started by nhldigest, Jan 30, 2008.

  1. #1
    Greetings,
    I'm hoping someone can help me with a piece of code that I can wrap around an ad in my sidebar so that the ad shows on the homepage/index page only and not on post pages.
    Any help would be greatly appreciated.
    Thank you in advance for your time and efforts.
     
    nhldigest, Jan 30, 2008 IP
  2. nhldigest

    nhldigest Peon

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I managed to find a piece of code that works. I thought I would post it here in case anyone else needs a similar fix for their wordpress site:
    As for Adsense - best performing ad format is the 250x300, so consider using something like that, showing either at the top left or top right of your post.

    <?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>
    Advertisement code goes here and is displayed on the homepage only
    <?php } ?>
     
    nhldigest, Jan 30, 2008 IP
  3. No.2

    No.2 Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks. Was looking for someting to show on the home page put not the other pages. Perfect.
     
    No.2, Mar 3, 2008 IP
  4. NewToAllThis

    NewToAllThis Peon

    Messages:
    741
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Is there a code to place ads everywhere EXCEPT on the home page? This code is perfect but it leaves a gap on other pages where the ads were.
     
    NewToAllThis, Aug 8, 2008 IP
  5. mayurjango

    mayurjango Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #5
    This is the perfect code:

    <?php if (is_home()) {
    ?>
    Advertisement code which is displayed on homepage only
    <?php
    }
    ?>

    Replace home with single to display ad on single page only.
    Cheers :D
     
    mayurjango, Apr 5, 2009 IP
    Rajaie likes this.
  6. ProDom

    ProDom Peon

    Messages:
    199
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Agreed, the above code works if you have to show the sidebar only on the homepage. But as per different requirements, I wanted to show sidebar on all pages but the homepage. I googled and found these two links which I found interesting (One) (Two)
     
    ProDom, Oct 31, 2009 IP
  7. FunMan

    FunMan Member

    Messages:
    315
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #7
    It was of great help. Thanks you very much.
    This type of clear and precise post are really helpful.
     
    FunMan, Mar 14, 2010 IP
  8. marshallallen250

    marshallallen250 Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    is there any plugin available?
     
    marshallallen250, Aug 26, 2010 IP
  9. rentdn

    rentdn Well-Known Member

    Messages:
    1,236
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    195
    #9
    Above codes are not working on my blogs
     
    rentdn, Sep 17, 2010 IP
  10. extremephp

    extremephp Peon

    Messages:
    1,290
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #10
    <?php
    $homepage = "/";
    $currentpage = $_SERVER['REQUEST_URI'];
    if($homepage==$currentpage) {
    echo 'Adcode here' ;
    }
    ?>

    This Will Work :) And I use this :D

    ~Exp~
     
    extremephp, Sep 17, 2010 IP
    jdR!pper likes this.