Wordpress输出完整图像而不是缩略图

时间:2014-12-12 20:02:06

标签: wordpress thumbnails

我有一个脚本显示上传到帖子的前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">';
        }
    }
}

谢谢

1 个答案:

答案 0 :(得分:0)

你在主题/ functions.php中声明了吗?如果不是WordPress将不会生成缩略图 实施例

add_image_size( 'homepage-thumb', 220, 180, true );

然后在你的主题调用中像现在一样。此外,您必须尝试使用​​此插件强制重新生成缩略图:https://wordpress.org/plugins/regenerate-thumbnails/

相关问题