^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 5年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云1核2g仅需102元/年,今日10点开抢

wordpress函数adjacent_image_link()用法示例

adjacent_image_link( bool $prev = true,  string|array $size = 'thumbnail',  bool $text = false )

Displays next or previous image link that has the same post parent.


描述

Retrieves the current attachment object from the $post global.


参数

$prev

(bool)
(Optional)
Whether to display the next (false) or previous (true) link.

Default value: true

$size

(string|array)
(Optional)
Image size. Accepts any valid image size, or an array of width and height values in pixels (in that order).

Default value: ‘thumbnail’

$text

(bool)
(Optional)
Link text.

Default value: false


源代码

File: wp-includes/media.php

function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) {
	$post = get_post();
	$attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );

	foreach ( $attachments as $k => $attachment ) {
		if ( $attachment->ID == $post->ID ) {
			break;
		}
	}

	$output = '';
	$attachment_id = 0;

	if ( $attachments ) {
		$k = $prev ? $k - 1 : $k + 1;

		if ( isset( $attachments[ $k ] ) ) {
			$attachment_id = $attachments[ $k ]->ID;
			$output = wp_get_attachment_link( $attachment_id, $size, true, false, $text );
		}
	}

	$adjacent = $prev ? 'previous' : 'next';

	/**
	 * Filters the adjacent image link.
	 *
	 * The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,
	 * either 'next', or 'previous'.
	 *
	 * @since 3.5.0
	 *
	 * @param string $output        Adjacent image HTML markup.
	 * @param int    $attachment_id Attachment ID
	 * @param string $size          Image size.
	 * @param string $text          Link text.
	 */
	echo apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text );
}

更新日志

Version 描述
2.5.0 Introduced.

相关函数

Uses

  • wp-includes/post.php:
    get_children()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/post-template.php:
    wp_get_attachment_link()
  • wp-includes/media.php:
    {$adjacent}_image_link
  • wp-includes/post.php:
    get_post()

Used By

  • wp-includes/media.php:
    previous_image_link()
  • wp-includes/media.php:
    next_image_link()

User Contributed Notes

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈