我目前有 <?php the_post_thumbnail('post-thumbnail', array('class' => "search-thumb attachment-post-thumbnail")); ?>
內的一個div,其中包含搜索結果標題和摘錄。我試圖實現的是ONLY
如果帖子有可用,則添加縮略圖。僅當縮略圖可用時纔將縮略圖添加到搜索結果中?
我的理由是因爲添加一個縮略圖會使div的高度變大。 讓我們說,縮略圖的div是150px的高度。如果搜索結果中沒有縮略圖,我想消除高度並僅使文本適合文本。 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內
HTML顯示高度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 //
screenshot http://i49.tinypic.com/2vv73oh.png