• 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 https://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: https://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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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.

    Thread Starter mithrustt

    (@mithrustt)

    Unfourtunately, it didn’t change a thing.

    hi, advertising my own plugin here, but if you use Widget Logic (https://www.ads-software.com/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

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

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

    { simplified the code for you }

    Thread Starter mithrustt

    (@mithrustt)

    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.

    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.

    Samsara, yes

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

    would mean if it’s “not home” then display the “code to be displayed”

    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 ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Show advertisement only on home page’ is closed to new replies.