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內容。

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