我希望我能解释一下我在这里的目的。在我当前项目的主页上,我将显示每篇文章的特色图片拇指,以及文章内容的摘录。在每个实际的贴子页面中,都有一个默认的WP库,其中包含2到4个图像。
我想做的是,让我的客户不必在每篇文章中都使用特色图片,这样缩略图就会始终显示在主页上。换言之,现在,他必须选择一幅图片作为特色,以便在主页上的每个循环中都有代表性的缩略图。
我可以这样做吗?即使他没有为帖子选择一个特色图片,仍然有一个缩略图来代表帖子?如果没有选择特色图片,我可以让它自动拾取帖子库中的第一张图片吗?
以防万一,以下是我正在使用的一些代码:
<div id="image-wrap">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</div><!--end image-wrap-->
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php the_title(\'<h2 class="entry-title"><a href="\' .
get_permalink() . \'" title="\' . the_title_attribute(\'echo=0\') . \'"
rel="bookmark">\', \'</a></h2>\'); ?>
<div class="entry-content">
<?php the_content(__(\'Continue reading\', \'example\')); ?>
<?php wp_link_pages(\'before=<p class="pages">\' . __(\'Pages:\',\'example\') .
\'&after=</p>\'); ?>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<p class="no-posts"><?php _e(\'Sorry, no posts matched your criteria\',
\'example\'); ?></p>
<?php endif; ?>
<?php wp_reset_query(); ?>
然后这是我的函数文件: // This theme uses post thumbnails
add_theme_support( \'post-thumbnails\' );
set_post_thumbnail_size( 150, 100, true );
// Automatically makes featured image thumbs a clickable link
add_filter( \'post_thumbnail_html\', \'my_post_image_html\', 10, 3 );
function my_post_image_html( $html, $post_id, $post_image_id ) {
$html = \'<a href="\' . get_permalink( $post_id ) . \'" title="\' . esc_attr(
get_post_field( \'post_title\', $post_id ) ) . \'">\' . $html . \'</a>\';
return $html;
}
// This theme displays full size featured image on the Post\'s page
function InsertFeaturedImage($content) {
global $post;
$original_content = $content;
if ( current_theme_supports( \'post-thumbnails\' ) ) {
if ((is_page()) || (is_single())) {
$content = the_post_thumbnail(\'page-single\');
$content .= $original_content;
}
}
return $content;
}
add_filter( \'the_content\', \'InsertFeaturedImage\' );
http://dependablecarcompany.com 如果你想知道我在说什么的话,那就是地址。当你看到标题为“1991 GMC Sierra”的帖子时,你就会明白我的意思。我没有为帖子使用特色图片,因此没有显示缩略图。提前感谢!