我很好地使用了这个实现--您可以看到它是如何抓住它的:
$thumbnails = get_posts(array(\'numberposts\'=>1,\'orderby\'=>\'ASC\',\'meta_key\' => \'_thumbnail_id\'));
然后,您可以转到“numberposts”=>3并构建缩略图结构:
<?php if ( has_post_thumbnail() ) {
global $post;
$thumbnails = get_posts(array(\'numberposts\'=>3,\'orderby\'=>\'ASC\',\'meta_key\' => \'_thumbnail_id\'));
foreach ($thumbnails as $thumbnail) {
echo \'<a href="\' . get_permalink( $post->ID ) . \'" title="\' . esc_attr( $post->post_title ) . \'">\';
echo get_the_post_thumbnail($thumbnail->ID, \'small-thumb\', array( \'alt\' => esc_attr( $post->post_title ), \'title\' => esc_attr( $post->post_title ) ));
echo \'</a>\';
}
?>
已编辑:不要忘记设置缩略图大小:
echo get_the_post_thumbnail($thumbnail->ID, \'small-thumb\', array( \'alt\' => esc_attr( $post->post_title ), \'title\' => esc_attr( $post->post_title ) ));
将“小拇指”更改为已设置的任何大小,如果需要设置一些大小,可以将其放入函数中。php:
//Add support, if you need it.
if ( function_exists( \'add_theme_support\' ) ) {
add_theme_support( \'post-thumbnails\' );
set_post_thumbnail_size( 960, 276, true ); // default Post Thumbnail dimensions
}
//Set them sizes, yo
if ( function_exists( \'add_image_size\' ) ) {
add_image_size( \'large-thumb\', 960, 276, true ); //(cropped)
add_image_size( \'medium-thumb\', 605, 174 ); // 605px wide, 174 high, not cropped
add_image_size( \'small-thumb\', 288, 83, true ); //(cropped)
add_image_size( \'small-square\', 100, 100, true ); //(cropped)
}
干杯,