I currently have the
<?php the_post_thumbnail('post-thumbnail', array( 'class' => "search-thumb attachment-post-thumbnail")); ?>
inside of a div that holds the Search Result Title, and Excerpt. What I'm trying to achieve is ONLY
adding the thumbnail if the post has it available.
My reason for this is because adding a thumbnail will make the div's height larger. Let's say the div with the thumbnail is 150px in height. I'd like to eliminate the height and have the div fit ONLY the text if the search result has no thumbnail.
HTML within search.php//
<?php get_header(); ?>
<div id="container" class="clearfix">
<div id="content-wrap">
<h1 class="heading1">Search Results</h1>
<div class="br"></div>
<div class="clear"></div>
<h2><?php echo 'Items Found ' . $wp_query->found_posts; ?></h2>
<div class="clear"></div>
<?php if(have_posts()): ?> <?php while(have_posts()) : the_post(); ?>
<div class="s-res">
<h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<div class="search-thumb">
<?php the_post_thumbnail('post-thumbnail', array( 'class' => "search-thumb attachment-post-thumbnail")); ?>
</div>
<?php echo str_replace('[...]', '', get_the_excerpt()); ?>
</div>
<?php endwhile; ?>
<?php else : ?>
<i><?php _e('Sorry, but nothing matched your search criteria.<br> Please try again with different keywords.'); ?></i>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
CSS to show height ect//
.s-res {
height: 150px;
margin-bottom: 10px;
}
img.search-thumb {
float: left;
background: url(images/diag_lines.png) repeat;
height: 100px;
padding: 10px;
}
SCREENSHOT//
Just wrap your thumbnail div within a
if ( has_post_thumbnail() ) {...
conditional block. Here is how your code should look like when you make use of the function:I'd suggest that you first do a quick Google search before asking a question ;) This function is pretty easy to find, besides WordPress has a pretty good code documentation, so it's quite possible that you'll be able to find an answer to most of your questions there.