Hướng dẫn get image url by id wordpress - lấy url hình ảnh bằng id wordpress

WP_GET_ATTACHMENT_IMAGE_URL (int & nbsp; $ bottomment_id, String | int [] & nbsp; $ size & nbsp; = & nbsp; 'Hình thu nhỏ', bool & nbsp;int $attachment_id, string|int[] $size = 'thumbnail', bool $icon = false ): string|false

Nhận URL của một tệp đính kèm hình ảnh.


$attachment_id Intrequiredint Required

ID đính kèm hình ảnh.

$size chuỗi | int [] tùy chọnstring|int[] Optional

Kích cỡ hình. Chấp nhận bất kỳ tên kích thước hình ảnh đã đăng ký hoặc một mảng có giá trị chiều rộng và chiều cao trong pixel (theo thứ tự đó). Mặc định 'thumbnail'.

Mặc định: 'thumbnail'

$icon BOOLOPTIONALbool Optional

Liệu hình ảnh nên được coi là một biểu tượng.

Mặc định: false


Chuỗi | URL đính kèm sai hoặc sai nếu không có hình ảnh. Nếu $size không khớp với bất kỳ kích thước hình ảnh đã đăng ký nào, URL hình ảnh gốc sẽ được trả về. Attachment URL or false if no image is available. If $size does not match any registered image size, the original image URL will be returned.


Tệp: wp-includes/media.php. Xem tất cả các tài liệu tham khảo

function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
	$image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
	return isset( $image[0] ) ? $image[0] : false;
}

Xem trên Tracview trên GitHub View on GitHub



Thay đổi
Phiên bảnSự mô tả
4.4.0 Được giới thiệu.

WP_GET_ATTACHMENT_IMAGE_SRC (int & nbsp; $ bottomment_id, String | int [] & nbsp; $ size & nbsp; = & nbsp; 'Hình thu nhỏ', bool & nbsp;int $attachment_id, string|int[] $size = 'thumbnail', bool $icon = false ): array|false

Lấy một hình ảnh để đại diện cho một tệp đính kèm.


$attachment_id Intrequiredint Required

ID đính kèm hình ảnh.

$size chuỗi | int [] tùy chọnstring|int[] Optional

Kích cỡ hình. Chấp nhận bất kỳ tên kích thước hình ảnh đã đăng ký hoặc một mảng có giá trị chiều rộng và chiều cao trong pixel (theo thứ tự đó). Mặc định 'thumbnail'.

Mặc định: 'thumbnail'

$icon BOOLOPTIONALbool Optional

Liệu hình ảnh có trở lại biểu tượng loại MIME hay không.

Mặc định: false


Mảng | Mảng sai của dữ liệu hình ảnh hoặc Boolean Sai nếu không có hình ảnh. Array of image data, or boolean false if no image is available.

  • sợi dây

    URL nguồn hình ảnh.

  • function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
    	// Get a thumbnail or intermediate image if there is one.
    	$image = image_downsize( $attachment_id, $size );
    	if ( ! $image ) {
    		$src = false;
    
    		if ( $icon ) {
    			$src = wp_mime_type_icon( $attachment_id );
    
    			if ( $src ) {
    				/** This filter is documented in wp-includes/post.php */
    				$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
    
    				$src_file               = $icon_dir . '/' . wp_basename( $src );
    				list( $width, $height ) = wp_getimagesize( $src_file );
    			}
    		}
    
    		if ( $src && $width && $height ) {
    			$image = array( $src, $width, $height, false );
    		}
    	}
    	/**
    	 * Filters the attachment image source result.
    	 *
    	 * @since 4.3.0
    	 *
    	 * @param array|false  $image         {
    	 *     Array of image data, or boolean false if no image is available.
    	 *
    	 *     @type string $0 Image source URL.
    	 *     @type int    $1 Image width in pixels.
    	 *     @type int    $2 Image height in pixels.
    	 *     @type bool   $3 Whether the image is a resized image.
    	 * }
    	 * @param int          $attachment_id Image attachment ID.
    	 * @param string|int[] $size          Requested image size. Can be any registered image size name, or
    	 *                                    an array of width and height values in pixels (in that order).
    	 * @param bool         $icon          Whether the image should be treated as an icon.
    	 */
    	return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );
    }
    
    6intint

    Chiều rộng hình ảnh tính bằng pixel.

  • function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
    	// Get a thumbnail or intermediate image if there is one.
    	$image = image_downsize( $attachment_id, $size );
    	if ( ! $image ) {
    		$src = false;
    
    		if ( $icon ) {
    			$src = wp_mime_type_icon( $attachment_id );
    
    			if ( $src ) {
    				/** This filter is documented in wp-includes/post.php */
    				$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
    
    				$src_file               = $icon_dir . '/' . wp_basename( $src );
    				list( $width, $height ) = wp_getimagesize( $src_file );
    			}
    		}
    
    		if ( $src && $width && $height ) {
    			$image = array( $src, $width, $height, false );
    		}
    	}
    	/**
    	 * Filters the attachment image source result.
    	 *
    	 * @since 4.3.0
    	 *
    	 * @param array|false  $image         {
    	 *     Array of image data, or boolean false if no image is available.
    	 *
    	 *     @type string $0 Image source URL.
    	 *     @type int    $1 Image width in pixels.
    	 *     @type int    $2 Image height in pixels.
    	 *     @type bool   $3 Whether the image is a resized image.
    	 * }
    	 * @param int          $attachment_id Image attachment ID.
    	 * @param string|int[] $size          Requested image size. Can be any registered image size name, or
    	 *                                    an array of width and height values in pixels (in that order).
    	 * @param bool         $icon          Whether the image should be treated as an icon.
    	 */
    	return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );
    }
    
    7intint

    Chiều cao hình ảnh trong pixel.

  • function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
    	// Get a thumbnail or intermediate image if there is one.
    	$image = image_downsize( $attachment_id, $size );
    	if ( ! $image ) {
    		$src = false;
    
    		if ( $icon ) {
    			$src = wp_mime_type_icon( $attachment_id );
    
    			if ( $src ) {
    				/** This filter is documented in wp-includes/post.php */
    				$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
    
    				$src_file               = $icon_dir . '/' . wp_basename( $src );
    				list( $width, $height ) = wp_getimagesize( $src_file );
    			}
    		}
    
    		if ( $src && $width && $height ) {
    			$image = array( $src, $width, $height, false );
    		}
    	}
    	/**
    	 * Filters the attachment image source result.
    	 *
    	 * @since 4.3.0
    	 *
    	 * @param array|false  $image         {
    	 *     Array of image data, or boolean false if no image is available.
    	 *
    	 *     @type string $0 Image source URL.
    	 *     @type int    $1 Image width in pixels.
    	 *     @type int    $2 Image height in pixels.
    	 *     @type bool   $3 Whether the image is a resized image.
    	 * }
    	 * @param int          $attachment_id Image attachment ID.
    	 * @param string|int[] $size          Requested image size. Can be any registered image size name, or
    	 *                                    an array of width and height values in pixels (in that order).
    	 * @param bool         $icon          Whether the image should be treated as an icon.
    	 */
    	return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );
    }
    
    8boolbool

    Cho dù hình ảnh là một hình ảnh kích thước.


Tệp: wp-includes/media.php. Xem tất cả các tài liệu tham khảo

function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
	// Get a thumbnail or intermediate image if there is one.
	$image = image_downsize( $attachment_id, $size );
	if ( ! $image ) {
		$src = false;

		if ( $icon ) {
			$src = wp_mime_type_icon( $attachment_id );

			if ( $src ) {
				/** This filter is documented in wp-includes/post.php */
				$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );

				$src_file               = $icon_dir . '/' . wp_basename( $src );
				list( $width, $height ) = wp_getimagesize( $src_file );
			}
		}

		if ( $src && $width && $height ) {
			$image = array( $src, $width, $height, false );
		}
	}
	/**
	 * Filters the attachment image source result.
	 *
	 * @since 4.3.0
	 *
	 * @param array|false  $image         {
	 *     Array of image data, or boolean false if no image is available.
	 *
	 *     @type string $0 Image source URL.
	 *     @type int    $1 Image width in pixels.
	 *     @type int    $2 Image height in pixels.
	 *     @type bool   $3 Whether the image is a resized image.
	 * }
	 * @param int          $attachment_id Image attachment ID.
	 * @param string|int[] $size          Requested image size. Can be any registered image size name, or
	 *                                    an array of width and height values in pixels (in that order).
	 * @param bool         $icon          Whether the image should be treated as an icon.
	 */
	return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );
}

Xem trên Tracview trên GitHub View on GitHub


Ứng dụng_filters ('icon_dir', chuỗi $ path)( 'icon_dir', string $path )

Lọc đường dẫn thư mục biểu tượng.

Ứng dụng_filters ('wp_get_attachment_image_src', mảng | false $ Image, int $ đính kèm_id, chuỗi | int [] $ size, bool $ icon)( 'wp_get_attachment_image_src', array|false $image, int $attachment_id, string|int[] $size, bool $icon )

Lọc kết quả nguồn hình ảnh đính kèm.



Thay đổi
Phiên bảnSự mô tả
2.5.0 Được giới thiệu.

Làm cách nào để tìm URL của hình ảnh WordPress?

Tìm URL hình ảnh WordPress của bạn từ Frontend Mở một trang hoặc đăng nơi hình ảnh được công bố và xác định vị trí hình ảnh. Sau đó, nhấp chuột phải vào hình ảnh và chọn tùy chọn 'Mở hình ảnh trong tab mới'. Khi hình ảnh mở trong tab mới, hãy nhìn vào URL trong thanh địa chỉ. Đó là URL hình ảnh WordPress của bạn.Open a page or post where the image is published and locate the image. After that, right-click on the image, and select 'Open image in new tab' option. Once the image opens in the new tab, look at the URL in the address bar. That is your WordPress image URL.

Làm thế nào để tôi tìm thấy URL hình ảnh nổi bật của tôi?

Chỉ cần thêm: add_theme_support ('post-thumbnails'); vào tệp chức năng của chủ đề.php và bạn sẽ nhận được một mô-đun hình ảnh đặc trưng trên màn hình quản trị cho các bài đăng cho phép bạn chọn một.add: add_theme_support('post-thumbnails'); To a theme's functions. php file and you'll get a Featured Image module on the admin screen for posts which allows you to select one.

Làm cách nào để tìm URL của tệp WordPress?

Bước 1 - Trong phần phụ trợ WordPress, Goto Left Menu Media -> Thư viện, tìm tệp phương tiện, sau đó nhấp vào liên kết chỉnh sửa. Step 2 - In the Edit Media page, copy the URL from the right side File URL input box.

Làm cách nào để tìm ID tệp đính kèm của tôi?

Để có được ID của tệp đính kèm, bạn phải đọc vấn đề cho danh sách các tệp đính kèm của nó./rest/api/2/vấn đề/(khóa vấn đề)?Các trường = tệp đính kèm nên làm điều đó.ID đính kèm đều là duy nhất, không phân biệt nội dung và tên tệp, bạn sẽ cần đọc mọi vấn đề đã bị ảnh hưởng.read the issue for its list of attached files. /rest/api/2/issue/(issue key)? fields=attachment should do it. Attachment ids are all unique, irrespective of the file content and name, you'll need to read every issue that has been affected.