wp_get_attachment_thumb_url()返回附件的缩略图(特色图像)URL网址

目录

描述

译文

检索附件缩略图的URL

原文

Retrieve URL for an attachment thumbnail.

wp_get_attachment_thumb_url() 描述

用法

<?php wp_get_attachment_thumb_url$attachment_id ); ?>

wp_get_attachment_thumb_url() 用法

参数

$attachment_id

(integer) (可选) Attachment ID

默认值: 0

wp_get_attachment_thumb_url() 参数

返回值

(string|boolean

False on failure. Thumbnail URL on success.

wp_get_attachment_thumb_url() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php 
$thumb_id = 25;
$url = wp_get_attachment_thumb_url( $thumb_id );
?>
<img src="<?php echo $url ?>"/>

wp_get_attachment_thumb_url() 示例

历史

添加于 版本: 2.1.0

wp_get_attachment_thumb_url() 历史

源文件

wp_get_attachment_thumb_url() 函数的代码位于 wp-includes/post.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve URL for an attachment thumbnail.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return string|false False on failure. Thumbnail URL on success.
 */
function wp_get_attachment_thumb_url( $post_id = 0 ) {
	$post_id = (int) $post_id;
	if ( !$post = get_post( $post_id ) )
		return false;
	if ( !$url = wp_get_attachment_url( $post->ID ) )
		return false;

	$sized = image_downsize( $post_id, 'thumbnail' );
	if ( $sized )
		return $sized[0];

	if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) )
		return false;

	$url = str_replace(basename($url), basename($thumb), $url);

	/**
	 * Filter the attachment thumbnail URL.
	 *
	 * @since 2.1.0
	 *
	 * @param string $url     URL for the attachment thumbnail.
	 * @param int    $post_id Attachment ID.
	 */
	return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID );
}

wp_get_attachment_thumb_url() 源文件

相关