• Hi all,

    I have a standard blog, and am trying to create ad space that will display ONLY on the first page of posts. Once a user goes to the previous page (/page/2) that ad space will no longer appear.

    I figured I could do a conditional, but for some reason it’s not working correctly for me.

    I’ve tried something like this, to test:
    `<?php if (is_front_page()){ ?>
    <p>Home Page</p>
    <?php else { ?>
    <p>Not Home Page</p>
    <?php } ?>
    ?>’

    I’ve also tried is_home() instead of is_front_page… neither work. My outcome is that “Home Page” displays on not just the homepage, but also all the previous pages of blog posts.

    Any suggestions? Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • Try:

    <?php if (is_front_page() && !is_paged() ){ ?>
    <p>Home Page</p>
    <?php else { ?>
    <p>Not Home Page</p>
    <?php } ?>
    ?>
    Thread Starter dbcuadro

    (@dbcuadro)

    Hi esmi,

    Thanks for your response. Seems like it throws an error when I insert that chunk in my index.php. Could’ve sworn it didn’t break the page yesterday.

    I am inserting it right after the <?php endwhile; ?> tag, but before the <?php else : ?> … and this is where I get the error, an unexpected T_ELSE.

    I’m sure there’s something really straight-forward I am overlooking. Any hints?

    also would it be advisable to do something even simpler, such as:

    <?php if (is_front_page() && !is_paged()) {
    		echo 'blah blah';
    	} endif; ?>

    I tried this and received the same T_ELSE error.

    Thanks again.

    Typo copied over from your original code. Try

    <?php if (is_front_page() && !is_paged() ){ ?>
    <p>Home Page</p>
    <?php else { ?>
    <p>Not Home Page</p>
    <?php } ?>
    Thread Starter dbcuadro

    (@dbcuadro)

    Forgot to mention that I found that error and already omitted it. Still getting the same T_ELSE error.

    Here is my index.php, if this helps:

    <?php
    /**
     * @package WordPress
     * @subpackage BlahBlah
     */
    
    get_header(); ?>
    
    <?php if (have_posts()) : ?>
    
    	<?php while (have_posts()) : the_post(); ?>
    
    		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<h2><span class="rtfb"><?php if (function_exists('tweetmeme')) echo tweetmeme();?><?php //echo facebook_sharecount(); ?></span><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    			<p class="date"><?php the_time('F jS, Y') ?></p>
    			<?php the_content('Read the rest of this entry &raquo;'); ?>
    
    			<div class="postFooter">
    				<p><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    			</div><!-- postFooter -->
    		</div><!-- post post post -->
    
    	<?php endwhile; ?>
    
    	<?php SEO_pager() ?>
    
    <?php else : ?>
    
    	<h2>Not Found</h2>
    	<p>Sorry, but you are looking for something that isn't here.</p>
    		<div id="search">
    			<?php get_search_form(); ?>
    		</div><!-- search -->
    
    <?php endif; ?>
    
    </div><!-- contentMain -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    I’m trying to insert this if statement between the endwhile and the call to seo_pager.

    Try:

    <?php endwhile; ?>
    
    <?php if( is_front_page() && !is_paged() ) : ?>
    <p>Home Page</p>
    
    <?php else : ?>
    <p>Not Home Page</p>
    
    <?php endif; ?>
    
    <?php SEO_pager() ?>

    Thanks, this works perfectly.
    I wanted to show slideshow only on homepage, but was getting error.

    Thread Starter dbcuadro

    (@dbcuadro)

    Brilliant. Thanks for your help.

    Thread Starter dbcuadro

    (@dbcuadro)

    After some further testing, I noticed this works on pages and single post pages, but if on the regular timeline and going through previous pages (https://example.com/page/2/, https://example.com/page/3/, etc.), it does not apply.

    Is there a way to get this to apply to previous pages on the timeline?

    Thanks again.

    Thread Starter dbcuadro

    (@dbcuadro)

    Just checking in, anyone have ideas on this issue? I feel like it’s so straight-forward but I haven’t been able to find an answer that works. Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘have element display ONLY on first page of posts’ is closed to new replies.