Support » Fixing WordPress » Issues w/Conditional Tag – Content Showing on All Pages

  • Resolved jeffreyarchibald



    Making a magazine-style WordPress theme, and I’m having issues with the <?php if(is_home())?> conditional tag.

    I’m trying to show a content slider on my index.php page, and only that page. However, when I navigate to page 2, the slider is still there. Here is my code snippet:

    <?php if (is_home()) { ?>
    <div id="slider">
    		        $featuredPosts = new WP_Query();
    		        while ($featuredPosts->have_posts()) : $featuredPosts->the_post();
    				$do_not_duplicate[] = get_the_ID();
    <li><a class='bottom' href='<?php the_permalink() ?>'><h2><?php the_title(); ?></h2></a><img src='<?php echo get_post_meta($post->ID, 'featuredpic', $single = true); ?>' alt='<?php the_title(); ?>'  />
    <?php endwhile; ?>
    <?php } ?>

    Any help would be awesome. I’ve been working on this all night! Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • index.php is not a page. It is the php template that is used to display your default page and any other posts/pages that do not have their own template.

    Is your home page the main blog page or a static page? If it’s a static page, try is_page instead of is_home.

    Also, if it’s a static page try putting your code into page.php and if it’s the main blog page try putting your code into archive.php. You may be putting it into the wrong template file.



    Forum Moderator


    if i get this right:
    if you go to a paginated page of your articles, you don’t want the slider:

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

    check with the documentation:

    Dear alchymyth: you are AWESOME. That was totally it. I went through a ton of the related documentation but missed this snippet. Much appreciated.

    SS_Minnow; thanks for the input as well. I did read up on the is_page vs. is_home issues; that part of my code is correct.

    Great. I learned something too. I didn’t pay close enough attention to where you wrote “when I navigate to page 2” so I missed the fact that the content is paged.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Issues w/Conditional Tag – Content Showing on All Pages’ is closed to new replies.