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.

I got a question about Wordpress

Discussion in 'PHP' started by steveb, Aug 24, 2011.

  1. #1
    I'm a PHP newbie and I have a question about implementing ads on Wordpress.

    If I want to show ads only on the homepage, category and page, how do I do this?

    I have tried:
    function header_ad() {
        if (is_home()) || (is_category()) || (is_page()) { ?>
    Code (markup):
    But, it doesn't work.

    Any advice would be appreciated.
     
    steveb, Aug 24, 2011 IP
  2. aandamar

    aandamar Well-Known Member

    Messages:
    243
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    3
    #2
    I'm just a noob like you.

    try this mate,

    
    <?php
    function header_ad() {
    /** Your function to show ad **/
    } ?>
    
    <?php if (is_home()) || (is_category()) || (is_page()) { ?>
       <?php header_ad(); ?>
    <?php } ?>
    
    Code (markup):
     
    aandamar, Aug 24, 2011 IP
  3. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #3
    Just use a plugin, something like quick adsense, you can paste any advert code you like.
     
    MyVodaFone, Aug 24, 2011 IP
  4. lastminuteskideals

    lastminuteskideals Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if u use wp as a cms and use a 'page' as the homepage, you need to check if you're on homepage by the using the actual pageID e.g. is_page($pageID) or something similar as far as i remember.
     
    lastminuteskideals, Aug 24, 2011 IP
  5. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #5
    You don't need a set of PHP tags on every line.
    <?php
    
    function header_ad() {
    
     /** Your function to show ad **/ 
    
    } 
    ?>
    
    <?php
      if (is_home()) || (is_category()) || (is_page()) {
    
         header_ad();   
    
    } ?>
    PHP:
     
    Rukbat, Aug 24, 2011 IP
  6. sarhad12

    sarhad12 Active Member

    Messages:
    394
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    55
    #6
    easiest way is to go to your dashboard click widgets add text widget copy the code from adsense or any other advertiser and paste in the text area and press save!!!
     
    sarhad12, Aug 24, 2011 IP
  7. ultimateword

    ultimateword Greenhorn

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #7
    There are many plugins for almost any type of work in wordpress. Just google them and you can find multiple options.
     
    ultimateword, Aug 24, 2011 IP
  8. Web Dev

    Web Dev Peon

    Messages:
    214
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Best thing about Wordpress is that you can customize your blog the way you want it, and you can find some themes just for that:)
     
    Web Dev, Aug 24, 2011 IP
  9. Ciprian

    Ciprian Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #9
    is_home() could also be is_frontpage(). Also try in_category(), instead of is_category().
     
    Ciprian, Aug 28, 2011 IP