wp_get_attachment_thumb_url

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

wp_get_attachment_thumb_url: 這個函式檢索附件的縮圖的URL。它接受附件ID作為引數,並返回縮圖的URL。

檢索附件縮圖的URL。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_get_attachment_thumb_url( $post_id = 0 ) {
$post_id = (int) $post_id;
// This uses image_downsize() which also looks for the (very) old format $image_meta['thumb']
// when the newer format $image_meta['sizes']['thumbnail'] doesn't exist.
$thumbnail_url = wp_get_attachment_image_url( $post_id, 'thumbnail' );
if ( empty( $thumbnail_url ) ) {
return false;
}
/**
* Filters the attachment thumbnail URL.
*
* @since 2.1.0
*
* @param string $thumbnail_url URL for the attachment thumbnail.
* @param int $post_id Attachment ID.
*/
return apply_filters( 'wp_get_attachment_thumb_url', $thumbnail_url, $post_id );
}
function wp_get_attachment_thumb_url( $post_id = 0 ) { $post_id = (int) $post_id; // This uses image_downsize() which also looks for the (very) old format $image_meta['thumb'] // when the newer format $image_meta['sizes']['thumbnail'] doesn't exist. $thumbnail_url = wp_get_attachment_image_url( $post_id, 'thumbnail' ); if ( empty( $thumbnail_url ) ) { return false; } /** * Filters the attachment thumbnail URL. * * @since 2.1.0 * * @param string $thumbnail_url URL for the attachment thumbnail. * @param int $post_id Attachment ID. */ return apply_filters( 'wp_get_attachment_thumb_url', $thumbnail_url, $post_id ); }
function wp_get_attachment_thumb_url( $post_id = 0 ) {
	$post_id = (int) $post_id;

	// This uses image_downsize() which also looks for the (very) old format $image_meta['thumb']
	// when the newer format $image_meta['sizes']['thumbnail'] doesn't exist.
	$thumbnail_url = wp_get_attachment_image_url( $post_id, 'thumbnail' );

	if ( empty( $thumbnail_url ) ) {
		return false;
	}

	/**
	 * Filters the attachment thumbnail URL.
	 *
	 * @since 2.1.0
	 *
	 * @param string $thumbnail_url URL for the attachment thumbnail.
	 * @param int    $post_id       Attachment ID.
	 */
	return apply_filters( 'wp_get_attachment_thumb_url', $thumbnail_url, $post_id );
}

常見問題

FAQs
檢視更多 >