get_the_attachment_link

函数
get_the_attachment_link ( $id = 0, $fullsize = false, $max_dims = false, $permalink = false )
参数
  • (int) $id Optional. Post ID.
    Required:
  • (bool) $fullsize Optional. Whether to use full size image. Default false.
    Required:
    Default: false
  • (array) $max_dims Optional. Max image dimensions.
    Required:
    Default: false
  • (bool) $permalink Optional. Whether to include permalink to image. Default false.
    Required:
    Default: false
返回值
  • (string)
相关
  • wp_get_attachment_link()
定义位置
相关方法
get_attachment_linkthe_attachment_linkthe_attachment_linkswp_get_attachment_linkget_attachment_icon
引入
2.0.0
弃用
2.5.0

get_the_attachment_link: 这个函数检索到当前附件页的链接。它需要三个可选参数:要显示的图片大小,是否链接到图片文件,以及是否显示图片标题属性。它以字符串形式返回附件链接。

检索带链接的附件图像的HTML内容。

function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false, $permalink = false) {
	_deprecated_function( __FUNCTION__, '2.5.0', 'wp_get_attachment_link()' );
	$id = (int) $id;
	$_post = get_post($id);

	if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
		return __('Missing Attachment');

	if ( $permalink )
		$url = get_attachment_link($_post->ID);

	$post_title = esc_attr($_post->post_title);

	$innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
	return "<a href='$url' title='$post_title'>$innerHTML</a>";
}

常见问题

FAQs
查看更多 >