Question

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(); ?>
Was it helpful?

Solution

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; ?>

OTHER TIPS

get_the_post_thumbnail
http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail

<?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?>

Maybe this can help:
Add thumbnail to search results ONLY if the thumbnail is available?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top