Include thumbnail wordpress search results

I have the blank-theme wordpress theme, and would like in the search results also appear as a thumbnail. Is it possible?

search.php

<?php get_header(); ?>

    <?php if (have_posts()) : ?>

        <h2>Resultados de Búsqueda:</h2>

        <?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>

        <?php while (have_posts()) : the_post(); ?>

            <div <?php post_class() ?> id="post-<?php the_ID(); ?>">

                <h2><a href='<?php echo get_permalink($post->ID)?>'><?php the_title(); ?></a></h2>

                <?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>

                <div class="entry">

                    <?php the_excerpt(); ?>

                </div>

            </div>

        <?php endwhile; ?>

        <?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>

    <?php else : ?>

        <h2>Ningún tema encontrado...</h2>

    <?php endif; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

Related posts

Leave a Reply

2 comments

  1. By default search.php just output the search results title and short description (depends on theme).

    To show thumbnail as well just call the wordpress function the_post_thumbnail() within the loop.

    Try this:

    <div class="entry">
    
        <?php
            if ( has_post_thumbnail() ) { // check if the post Thumbnail
                the_post_thumbnail();
            } else {
                //your default img
            }
    
            the_excerpt(); //your short description
    ?>
    </div>
    

    Full Code:

    <?php if (have_posts()) : ?>
    
        <h2>Resultados de Búsqueda:</h2>
    
        <?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
    
        <?php while (have_posts()) : the_post(); ?>
    
            <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    
                <h2><a href='<?php echo get_permalink($post->ID)?>'><?php the_title(); ?></a></h2>
    
                <?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
    
                <div class="entry">
    
                    <?php
                        if ( has_post_thumbnail() ) { // check if the post Thumbnail
                            the_post_thumbnail();
                        } else {
                            //your default img
                        }
    
                        the_excerpt(); //your short description
                    ?>
                </div>
    
            </div>
    
        <?php endwhile; ?>
    
        <?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
    
    <?php else : ?>
    
        <h2>Ningún tema encontrado...</h2>
    
    <?php endif; ?>