0

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; ?>
5
  • 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)?!! Nov 9, 2013 at 18:11
  • I added an image to explain.
    – ccharms
    Nov 9, 2013 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? Nov 9, 2013 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, 2013 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, 2013 at 19:20

1 Answer 1

1

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 } ?>
3
  • For some reason it kept crashing.
    – ccharms
    Nov 9, 2013 at 19:47
  • I haven't checked the code, but turn debug on and the error message should help you fix any issues. Nov 9, 2013 at 22:08
  • a small correction to the logic: if( $wp_query->current_post != 0 || is_paged() )
    – Michael
    Nov 10, 2013 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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