[resolved] Issues w/Conditional Tag - Content Showing on All Pages (6 posts)

  1. jeffreyarchibald
    Posted 6 years ago #


    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.

  2. Jonas Grumby
    Posted 6 years ago #

    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.

  3. Jonas Grumby
    Posted 6 years ago #

    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.

  4. Michael
    Forum Moderator
    Posted 6 years ago #


    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:

  5. jeffreyarchibald
    Posted 6 years ago #

    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.

  6. Jonas Grumby
    Posted 6 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic