wp_get_attachment_link()
wp_get_attachment_link( int|WP_Post $id, string|array $…
wp_get_attachment_link( int|WP_Post $id, string|array $size = ‘thumbnail’, bool $permalink = false, bool $icon = false, string|false $text = false, array|string $attr = ” )
如果可能,请使用图像或图标检索附件页面链接。
Retrieve an attachment page link using an image or icon, if possible.
如果可能,请使用图像或图标检索附件页面链接。
Retrieve an attachment page link using an image or icon, if possible.
目录锚点:#参数#源码#笔记
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $id | (int | WP_Post) | Post ID或Post对象。 |
| $size | (string | array) | 图像大小。接受任何有效的图像大小,或以像素为单位的宽度和高度值数组(按该顺序)。 |
| $permalink | (bool) | 是否向图像添加永久链接。 |
| $icon | (bool) | 附件是否为图标。 |
| $text | (string | false) | 链接要使用的文本。通过传递字符串激活,否则为false。 |
| $attr | (array | string) | 属性的数组或字符串。 |
源码(Source)
/**
* Retrieve an attachment page link using an image or icon, if possible.
*
* @since 2.5.0
*
* @param int|WP_Post $id Optional. Post ID or post object.
* @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
* @param bool $permalink Optional, default is false. Whether to add permalink to image.
* @param bool $icon Optional, default is false. Whether to include icon.
* @param string|bool $text Optional, default is false. If string, then will be link text.
* @param array|string $attr Optional. Array or string of attributes.
* @return string HTML content.
*/
function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) {
$id = intval( $id );
$_post = get_post( $id );
if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )
return __( 'Missing Attachment' );
if ( $permalink )
$url = get_attachment_link( $_post->ID );
if ( $text ) {
$link_text = $text;
} elseif ( $size && 'none' != $size ) {
$link_text = wp_get_attachment_image( $id, $size, $icon, $attr );
} else {
$link_text = '';
}
if ( trim( $link_text ) == '' )
$link_text = $_post->post_title;
/**
* Filter a retrieved attachment page link.
*
* @since 2.7.0
*
* @param string $link_html The page link HTML output.
* @param int $id Post ID.
* @param string $size Image size. Default 'thumbnail'.
* @param bool $permalink Whether to add permalink to image. Default false.
* @param bool $icon Whether to include an icon. Default false.
* @param string|bool $text If string, will be link text. Default false.
*/
return apply_filters( 'wp_get_attachment_link', "$link_text", $id, $size, $permalink, $icon, $text );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 4.4.0 | wp-includes/post-template.php | 3 | 2 |
笔记(Notes)
将附件链接到帖子
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!