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。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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
查看更多 >