previous_image_link()
云策文档标注
概述
previous_image_link() 函数用于在附件页面中显示指向同一父文章的上一个图片链接。它通常用于附件页面,如 WordPress 默认主题中的 image.php。
关键要点
- 函数输出一个链接,指向当前附件所属文章的上一个图片附件。
- 接受两个参数:$size(图片尺寸,默认为 'thumbnail')和 $text(链接文本,默认为 false)。
- 与 get_previous_image_link() 相关,后者获取链接而不直接输出。
- 自 WordPress 2.5.0 版本引入。
代码示例
previous_image_link( $size, $text );注意事项
- 当传递数组作为 $size 参数时,不会创建新图片,而是由浏览器缩放缩略图,可能导致图像失真。
- 如果 $text 参数为 false,函数将使用图片的标题作为链接文本。
- 要指定自定义链接文本,需将第一个参数设为 false,第二个参数传递字符串。
原文内容
Displays previous image link that has the same post parent.
Parameters
$sizestring|int[]optional-
Image size. Accepts any registered image size name, or an array of width and height values in pixels (in that order). Default
'thumbnail'. $textstring|falseoptional-
Link text.
Default:
false
Source
function previous_image_link( $size = 'thumbnail', $text = false ) {
echo get_previous_image_link( $size, $text );
}
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
Skip to note 6 content
Codex
Basic Examples
Default Usage
Working example
<div class="alignleft"></div>Skip to note 7 content
Codex
Choose a Recognized Image Size
Skip to note 8 content
Codex
Define a Custom Image Size
Please note that passing an array as the first parameter will not create a new image; It will use the web browser to re-size the thumbnail to fit into the given dimensions. Although this works in a pinch, it produces a rather distorted view of the image due to the fact that browsers have no way of re sampling the re-sized image.
Skip to note 9 content
Codex
Use the Image’s Title as Link Text
If a Boolean false is used as the first parameter, The function will use the image’s title value (as set through the Media Library).
Skip to note 10 content
Codex
Use a Custom String as Link Text
To specify a custom string as the link text, pass a Boolean false as the first parameter and the custom text as a string to the second parameter.