WordPress画廊网址已损坏(不显示图片网址)

时间:2018-09-25 18:28:05

标签: php wordpress

我正在尝试存储外部图像,并使用它们创建图库。即使正确显示了150x150像素的缩略图,目标图像的URL也会损坏。

这是图库中的示例物品

<a href="http://domain.name/0000000135-1920x1080-18/">
    <img width="150" height="150" src="http://domain.name/wp-content/uploads/2018/09/0000000135.1920x1080-18-150x150.jpg" 
     class="attachment-thumbnail size-thumbnail" alt="">
</a>

php部分;

 $ids = [];
 foreach ( $game->images as $image ) {
 $_image = $this->upload_image( $image->path );
     array_push( $ids, $_image["id"] );
 }
 $imp     = implode( ",", $ids );
 $gallery = "[gallery ids='$imp']"; // I'm going to put shortcode inside of heredoc content
 $gallery = trim( $gallery, "'" );


 public function upload_image( $url ) {
    $image = [];
    require_once( ABSPATH . 'wp-admin/includes/media.php' );
    require_once( ABSPATH . 'wp-admin/includes/file.php' );
    require_once( ABSPATH . 'wp-admin/includes/image.php' );
    $image["src"] = media_sideload_image( $url, null, null, 'src' );
    $image["id"]  = attachment_url_to_postid( $image["src"] );

    return $image;
}

我该如何解决?

0 个答案:

没有答案