WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. jeffreyarchibald
    Member
    Posted 4 years ago #

    Hi,

    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">
    	<ul>
    		  <?php
    		        $featuredPosts = new WP_Query();
    		        $featuredPosts->query('category_name=featured&showposts=3');
    		        while ($featuredPosts->have_posts()) : $featuredPosts->the_post();
    				$do_not_duplicate[] = get_the_ID();
    				$postcount++;
    		    ?>
    
    <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(); ?>'  />
    
    			        </li>
    <?php endwhile; ?>
    		</ul>
    
    </div>
    </div>
    
    	<!--/slider-->
    
    <?php } ?>

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

  2. Jonas Grumby
    Member
    Posted 4 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
    Member
    Posted 4 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. alchymyth
    Forum Moderator
    Posted 4 years ago #

    @jeffreyarchibald

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

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

    check with the documentation:
    http://codex.wordpress.org/Conditional_Tags
    http://codex.wordpress.org/Conditional_Tags#A_Paged_Page

  5. jeffreyarchibald
    Member
    Posted 4 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
    Member
    Posted 4 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