【发布时间】:2023-03-07 00:23:01
【问题描述】:
我有一个脚本,可以显示上传到帖子的前 5 张图片。但是,输出将每个图像显示为完整的 url 而不是缩略图,因此加载时间比要求的要长。请问有人可以告诉我这个脚本哪里出错了吗?
网址是:http://tessabunney.functionpixel.com/projects/
脚本是:
add_action( 'after_setup_theme', 'theme_setup' );
function theme_setup() {
add_image_size( 'multimedia-thumb', 220, 180, true );
}
function echo_first_image( $postID ) {
$args = array(
'numberposts' => 5,
'order' => 'DEC',
'post_mime_type' => 'image',
'post_parent' => $postID,
'post_status' => null,
'post_type' => 'attachment',
);
$attachments = get_children( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
$image_attributes = wp_get_attachment_image_src( $attachment->ID, 'multimedia-thumb' ) ? wp_get_attachment_image_src( $attachment->ID, 'multimedia-thumb' ) : wp_get_attachment_image_src( $attachment->ID, 'multimedia-thumb' );
echo '<img src="' . wp_get_attachment_thumb_url( $attachment->ID ) . '" class="current">';
}
}
}
谢谢
【问题讨论】:
标签: wordpress thumbnails