• Hello,

    I’m trying to figure out how to display ads in my sidebar.php, but only on the homepage. I tried both code methods below, but the ads continue to show on every page. Can anyone help me troubleshoot why?

    <?php if ( is_front_page() ) { ?>
    HTML code for ads
    <?php } ?>

    <?php if ( is_home() ) { ?>
    HTML code for ads
    <?php } ?>

    *Notes:
    Settings>Reading>Front page displays: Your latest posts

    If I use the following code, the ads do not show up anywhere.

    <?php if (!is_home() ) { ?>
    HTML code for ads
    <?php } ?>

    <?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>
    HTML code for ads
    <?php } ?>

Viewing 11 replies - 1 through 11 (of 11 total)
  • hi

    try just this

    <?php if ( is_front_page() ) { ?>
    HTML code for ads
    <?php } ?>

    for historical reasons, is_home() does not refer to what most of us would call the home page but to the blog page. If the blog page is the home page then they are the same, otherwise not.

    Thread Starter mpttt

    (@mpttt)

    Thank you for your reply.

    It’s very strange. I see that code works for others, but for some reason not on my blog. What is in “HTML code for ads” still shows up on every page.

    I wonder if it could be the template, but no idea how to test what is wrong.

    Hi

    Check to see if you are using any widgets in that sidebar. If you are, the code in the sidebar file is not even being executed.

    Thread Starter mpttt

    (@mpttt)

    Hi,

    It’s pulling from the file sidebar.php, (no widgets via admin). However there is code for widgets in the sidebar.php file.

    Put a test message of some sort in the sidebar file, so it prints out in the sidebar, to confirm that your sidebar code is being executed – that’s step 1. while you’re at it, put a second message in the <?php if ( is_front_page() ) { ?> code – you want to see that message appear in the sidebar, to be certain that code is executing, and on all the pages as it appears to be.

    Thread Starter mpttt

    (@mpttt)

    Yep, that’s working. Both test messages are showing on every page.

    does you theme by any chance load all pages through the main page template – ajax or whatever?

    Thread Starter mpttt

    (@mpttt)

    It’s using a theme called Cutline 1.1

    Thread Starter mpttt

    (@mpttt)

    I verified it’s not using 1 main template page. It uses separate pages like index.php and single.php for the homepage and post pages.

    Hi

    I’m not suggesting that what you are saying is happening is not happening – obviously it is – I just don’t know what else to suggest you do.

    Something is going on outside of the scope of the code you are posting that is causing this to occur, since its not possible for is_front_page() to be true on every page.

    Thread Starter mpttt

    (@mpttt)

    Ok, thanks for trying. I appreciate your help.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Ads in Sidebar on Homepage only?’ is closed to new replies.