我有the blank-theme wordpress theme,并希望在搜索结果中也显示为缩略图。有可能吗?
的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(); ?>
答案 0 :(得分:2)
<强> get_the_post_thumbnail 强>
http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
<?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?>
也许这可以提供帮助:
Add thumbnail to search results ONLY if the thumbnail is available?
答案 1 :(得分:1)
默认情况下search.php
只输出搜索结果标题和简短描述(取决于主题)。
要显示缩略图,只需在循环中调用wordpress函数the_post_thumbnail()
。
试试这个:
<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>
完整代码:
<?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; ?>