您可以通过多种方式实现这一点,但如果您使用相对较新的wordpress,则应该使用\\u post\\u缩略图()。
您可以在函数中定义它。php,例如:
add_theme_support( \'post-thumbnails\' ); //thumnails set_post_thumbnail_size( 150,230, true ); // defaultpost thumbnails
add_image_size( \'your-custom-name-2\', 400, 9999 ); // some size thumbnail
add_image_size( \'your-custom-name-2\', 400, 300,false ); // another size
add_image_size( \'whatEverName\', 100, 100, false ); // yet another
“false”或“true”参数与裁剪模式有关(请参阅下文)
http://codex.wordpress.org/Function_Reference/the_post_thumbnail还有这里
Display thumbnail from custom field
然后,您应该在上载图像时定义一个后期默认图像(您将在上载屏幕上看到它),然后您可以在主题中调用它,如下所示:
the_post_thumbnail(\'whatEverName\');
//取决于您想要的尺寸。
然而,这将为您提供一个定义的图像。它还将为您提供图像本身。如果需要URL、大小或其他信息,应使用
get_the_post_thumbnail($page->ID, \'whatEverName\');
如果需要多个图像,可以使用以下选项:
<?php //GET THE FIRST IMAGE
$args = array(
\'order\' => \'ASC\',
\'orderby\' => \'menu_order\',
\'post_type\' => \'attachment\',
\'post_parent\' => $post->ID,
\'post_mime_type\' => \'image\',
\'post_status\' => null,
\'numberposts\' => 1, //change if you want another number
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
echo wp_get_attachment_link($attachment->ID, \'thumbnail\', false, false);
}
} ?>
// CONTENT AND OTHER STUFF...
<?php //GET ALL EXPECT FIRST IMAGE
$args = array(
\'order\' => \'ASC\',
\'orderby\' => \'menu_order\',
\'post_type\' => \'attachment\',
\'post_parent\' => $post->ID,
\'post_mime_type\' => \'image\',
\'post_status\' => null,
\'numberposts\' => -1,
);
$attachments = get_posts($args);
if ($attachments) {
$no_show=true;
foreach ($attachments as $attachment) {
if($no_show) {$no_show=false; continue; }
echo wp_get_attachment_link($attachment->ID, \'thumbnail\', false, false);
}
} ?>