函数文档

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

More Information

Usage:

Typically uses in attachment.php. In the WordPress default theme Twenty Eleven and Twenty Twelve, it is used in image.php.

previous_image_link( $size, $text );
Notes:

This creates a link to the previous image attached to the current post. Whenever a series of images are linked to the attachment page, it will put a ‘previous image link’ with the images when viewed in the attachment page.

Source

function previous_image_link( $size = 'thumbnail', $text = false ) {
	echo get_previous_image_link( $size, $text );
}

Changelog

Version Description
2.5.0 Introduced.

User Contributed Notes

  1. Skip to note 8 content

    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.