【问题标题】:Wordpress outputting full image instead of thumbnailWordpress 输出完整图像而不是缩略图
【发布时间】: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


    【解决方案1】:

    你在你的 theme/functions.php 中声明了吗?如果不是 WordPress 不会生成缩略图 示例

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

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

    【讨论】:

    • 是的,我之前尝试过,但我留下了我的自定义尺寸“多媒体拇指”,让您看到它不会影响它。我正在使用的代码已在上面更新,并且我重新生成了刚刚封装的缩略图:)
    • 尝试这样做以知道它是否真的在添加 add_action( 'after_setup_theme', 'theme_setup' ); function theme_setup() { add_image_size( 'homepage-thumb', 220, 180, true ); }
    • 您的服务器是否支持 PHP 中的 GD 库?使用 创建一个 info.php 文件并找到 gd 支持
    • 这可能是问题所在,但我将暂时搁置此问题,因为该站点将在接下来的几天内转移到另一台服务器。我会回来的! :)
    猜你喜欢
    • 2012-04-29
    • 1970-01-01
    • 1970-01-01
    • 2012-07-29
    • 2019-08-10
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    相关资源
    最近更新 更多