wp_get_attachment_thumb_file

函式
wp_get_attachment_thumb_file ( $post_id = 0 )
引數
  • (int) $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
    Required:
返回值
  • (string|false) Thumbnail file path on success, false on failure.
定義位置
相關方法
wp_get_attachment_thumb_urlwp_get_attachment_urlwp_ajax_set_attachment_thumbnailwp_get_attachment_imagewp_delete_attachment_files
引入
2.1.0
棄用
6.1.0

wp_get_attachment_thumb_file: 這個函式檢索一個附件的縮圖的檔案路徑。它接受附件ID作為引數,並返回縮圖的檔案路徑。

檢索一個附件的縮圖。

請注意,這隻適用於(非常)老的影象後設資料風格,其中’thumb’被設定,而’ sizes’陣列不存在。對於較新的影象後設資料風格,儘管’thumbnail’存在於’size’陣列中,該函式仍返回false。

function wp_get_attachment_thumb_file( $post_id = 0 ) {
	_deprecated_function( __FUNCTION__, '6.1.0' );

	$post_id = (int) $post_id;
	$post    = get_post( $post_id );

	if ( ! $post ) {
		return false;
	}

	// Use $post->ID rather than $post_id as get_post() may have used the global $post object.
	$imagedata = wp_get_attachment_metadata( $post->ID );

	if ( ! is_array( $imagedata ) ) {
		return false;
	}

	$file = get_attached_file( $post->ID );

	if ( ! empty( $imagedata['thumb'] ) ) {
		$thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file );
		if ( file_exists( $thumbfile ) ) {
			/**
			 * Filters the attachment thumbnail file path.
			 *
			 * @since 2.1.0
			 *
			 * @param string $thumbfile File path to the attachment thumbnail.
			 * @param int    $post_id   Attachment ID.
			 */
			return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
		}
	}

	return false;
}

常見問題

FAQs
檢視更多 >