仅当缩略图可用时才将缩略图添加到搜索结果中? [英] Add thumbnail to search results ONLY if the thumbnail is available?
问题描述
我目前拥有<?php the_post_thumbnail('post-thumbnail', array('class' => "search-thumb attachment-post-thumbnail"));?>
位于包含搜索结果标题和摘录的 div 中.我想要实现的是 ONLY
添加缩略图(如果帖子可用).
我这样做的原因是因为添加缩略图会使 div 的高度更大.假设带有缩略图的 div 的高度为 150 像素.如果搜索结果没有缩略图,我想消除高度并使 div 仅适合文本.
search.php 中的 HTML//
<div id="container" class="clearfix"><div id="content-wrap"><h1 class="heading1">搜索结果</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="书签"><?php the_title();?></a></h3><div class="search-thumb"><?php the_post_thumbnail('post-thumbnail', array('class' => "search-thumb attachment-post-thumbnail"));?>
<?php echo str_replace('[...]', '', get_the_excerpt());?>
<?php endwhile;?><?php 其他:?><i><?php _e('抱歉,没有符合您的搜索条件.<br>请使用不同的关键字再试一次.');?></i><?php endif;?>