WordPress.org

Ready to get started?Download WordPress

Forums

Twenty Twelve
Thumbnails on Search (11 posts)

  1. sdpate48
    Member
    Posted 1 year ago #

    Has anyone fixed showing thumbnails for post excerpts on a search? Thanks

  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    May you provide a link to the problematic webpage? To clarify, the issue is you don't have thumbnails on search results?

  3. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    the featured image is shown by this line in content.php (line 18):

    <?php the_post_thumbnail(); ?>

    wrap it into a conditional statement to exclude it in search results:

    <?php if( !is_search() )  the_post_thumbnail(); ?>
  4. sdpate48
    Member
    Posted 1 year ago #

    http://njnnetwork.com/?s=Samsung

    That's the search result

  5. sdpate48
    Member
    Posted 1 year ago #

    Tried <?php if( !is_search() ) the_post_thumbnail(); ?>

    but had earlier rem'd that statement to avoid double images on single posts - one above the Post title and another after h1

    Line 18 works <?php // the_post_thumbnail(); ?>

  6. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    ok - you want to have the post's image in the search result?
    (it seems that you were not referring to the 'featured image' aka post_thumbnail, but to a thumbnail in the post)

    before you proceed, strongly consider to create a child theme for your customisations; http://codex.wordpress.org/Child_Themes

    it is not recommended to edit any of the default themes directly.

    then edit content.php (a copy of content.php in your child theme):

    this section decides to show only excerpts for search results:

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    		<div class="entry-summary">
    			<?php the_excerpt(); ?>
    		</div><!-- .entry-summary -->
    		<?php else : ?>
    		<div class="entry-content">
    			<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    		</div><!-- .entry-content -->
    		<?php endif; ?>

    remove the conditional structure and leave only:

    <div class="entry-content">
    			<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    		</div><!-- .entry-content -->
  7. sdpate48
    Member
    Posted 1 year ago #

    Sorry for the terminology mixup. I want to display the smaller image which is called the '150 x 150 thumbnail' in insert media and I presumed is the 'featured image'

    Without modification, search results displays the excerpt without an image. A Category search displays the first post image, which I want to change to the 150x150 image as well but one thing at a time.

    I experimented with removing conditional statements as suggested but none of my versions got an image.
    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    <div class="entry-summary">
    <?php the_excerpt(); ?>
    </div><!-- .entry-summary -->
    <?php else : ?>
    ....
    <?php endif; ?>

  8. sdpate48
    Member
    Posted 1 year ago #

    I tried this code and got images, although not the right size (right after <?php if ( is_search() ) : // Only display Excerpts for Search ?>

                     <div class="the_post_thumbnail">
                     <?php the_post_thumbnail(150,150); ?>

    I put the 150 to enlarge some 50x50 thumbnails.

    What I want to do is size everything down to 150 pixels wide.

  9. sdpate48
    Member
    Posted 1 year ago #

    It's all working nicely except the text wrap

  10. sdpate48
    Member
    Posted 1 year ago #

    word wrap fixed by align left statement.

    <hre><?php if ( is_search() ) : // Only display Excerpts for Search ?>
    <div class="the_post_thumbnail">
    <?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?>

    Thanks for your help and also for the documentation. Function Reference/the post thumbnail

  11. sdpate48
    Member
    Posted 1 year ago #

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
         <div class="the_post_thumbnail">
         <?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?>
    

    fixed

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic