Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What I want to fix

I have set up my Wordpress to add the wordpress Featured Image thumbnails to all posts on the homepage.

How do I make the code skip adding [wordpress Featured Image thumbnails][3] to the first post [the_content() ~ in the code below] and only add them to [wordpress Featured Image thumbnails][4] the other posts [the_excerpt() ~ in the code below]?

Code I put in content.php to make it put [wordpress Featured Image thumbnails][5] on homepage. Link to pastebin code Here

    <?php if ( is_search() | is_home() ) : // Edit this to show excerpts in other areas of the theme?>
    <div class="entry-summary">
    <!-- This adds the post thumbnail/featured image -->
        <div class="excerpt-thumb"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
    <?php the_post_thumbnail('excerpt-thumbnail', 'class=alignleft'); ?></a></div>
                      <?php  if($wp_query->current_post == 0 && !is_paged()) { the_content(); } else { the_excerpt(); }     ?>                     


            </div><!-- .entry-summary -->
            <?php else : ?>
            <div class="entry-content">
                    <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?>
                    <?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
            </div><!-- .entry-content -->
            <?php endif; ?>
share|improve this question
    
I have edited the question but still not clear about something, let me ask it here. Do you want to show all the posts in the page except a post(you are calling it the first post)?!! –  Maruti Mohanty Nov 9 '13 at 18:11
    
I added an image to explain. –  ccharms Nov 9 '13 at 18:28
    
Sorry but this didn't help either. Can you elaborate where is the first image appearing and why do you want to remove it? and where does the bottom two images appear and why do you want to keep those? –  Maruti Mohanty Nov 9 '13 at 18:47
    
I made a code that takes the featured image (codex.wordpress.org/Post_Thumbnails) assigned from each post and creates thumbnail on the homepage. –  ccharms Nov 9 '13 at 19:19
    
The code, however does it for all of them. I only want it for the previews at the bottom (the ones noted in orange). –  ccharms Nov 9 '13 at 19:20
add comment

1 Answer

You've practically got the solution in the code ;)

Notice that the entire content of the first post is visilbe, but for the rest only the excerpt displays. That's from this (after tidying):

<?php 
if( $wp_query->current_post == 0 && !is_paged() ) { 
    the_content(); 
} else { 
    the_excerpt(); 
}
?>

So let's just apply that logic to the thumbnail part:

<?php if( $wp_query->current_post != 0 || !is_paged() ) { ?>

     <div class="excerpt-thumb">
          <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
               <?php the_post_thumbnail('excerpt-thumbnail', 'class=alignleft'); ?>
          </a>
     </div>

<?php } ?>
share|improve this answer
    
For some reason it kept crashing. –  ccharms Nov 9 '13 at 19:47
    
I haven't checked the code, but turn debug on and the error message should help you fix any issues. –  Stephen Harris Nov 9 '13 at 22:08
    
a small correction to the logic: if( $wp_query->current_post != 0 || is_paged() ) –  Michael Nov 10 '13 at 11:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.