私は現在
<?php the_post_thumbnail('post-thumbnail', array( 'class' => "search-thumb attachment-post-thumbnail")); ?>
、検索結果のタイトルと抜粋を保持する div の内部を持っています。私が達成しようとしているONLY
のは、投稿にサムネイルがある場合はサムネイルを追加することです。
これは、サムネイルを追加すると div の高さが大きくなるためです。サムネイルのある div の高さが 150px だとしましょう。検索結果にサムネイルがない場合は、高さをなくして div をテキストのみに合わせたいと思います。
search.php 内の HTML //
<?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 //
.s-res {
height: 150px;
margin-bottom: 10px;
}
img.search-thumb {
float: left;
background: url(images/diag_lines.png) repeat;
height: 100px;
padding: 10px;
}
スクリーンショット//