Forums

Show advertisement only on home page (9 posts)

  1. Mithrustt
    Member
    Posted 1 year ago #

    Edit: I just realized that I probably put this in the wrong forum. Move if necessary. Sorry.

    OK, so I have it so that there is two advertisements in my sidebar, however, I only want them both to show up on the home page, then when someone visits a single post of another page, only the first advertisement shows and the second one goes away.

    I have this code in my sidebar:

    <?php if (!( is_home() )) { ?>
    
                		<?php include('ad_side2.php'); ?>
    
                		<?php } ?>

    However, it seems to have the opposite effect. The site is www.think-theory.com. You can see on the home page that only the first ad shows up and not the second. Then, if you go to a post, like this one: www.think-theory.com/unreal-tournament-3/, both show up.

    So, it's doing the opposite of what I want. Does anyone know how I can switch this?

    Any help is greatly appreciated.

  2. johnkolbert
    Member
    Posted 1 year ago #

    Not sure if this will really make a difference, but try:

    <?php if (!is_home()) {
            include('ad_side2.php');
              } ?>

    The difference being I removed your parenthesis inbetween the exlamation and is_home. Give it a shot, not sure if it will change anything though.

  3. Mithrustt
    Member
    Posted 1 year ago #

    Unfourtunately, it didn't change a thing.

  4. alanft
    Member
    Posted 1 year ago #

    hi, advertising my own plugin here, but if you use Widget Logic (http://wordpress.org/extend/plugins/widget-logic/) you could use two generic widgets (say the usual text widgets) and specify logic to show the widgets when:

    is_home() || is_single()
    for one and
    is_home()
    for the other

  5. haochi
    Member
    Posted 1 year ago #

    It's because you are doing it the opposite way!!!

    <?php if(is_home()){include('ad_side2.php');} ?>

    { simplified the code for you }

  6. Mithrustt
    Member
    Posted 1 year ago #

    Oh, I see. It's the '!' that was saying that if it is not home, show the second ad, otherwise, don't show it.

    Thank you. All fixed now.

  7. Samsara
    Member
    Posted 1 year ago #

    What if I would like the opposite effect? I would like ads on all pages except for is_home? I am a php newb so just the basics?

    <?php if ( is_home() ) { ?> - if home then...whatever.

    What is the opposite of this statement?

    <?php if (!is_home() ) { ?>

    Is it the above?

    Thanks.

  8. johnkolbert
    Member
    Posted 1 year ago #

    Samsara, yes

    <?php if(!is_home()){
       code to be displayed
       }
    ?>

    would mean if it's "not home" then display the "code to be displayed"

  9. mayurjango
    Member
    Posted 7 months ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic