WordPress开发函数adjacent_image_link()

WordPress开发函数adjacent_i**ge_link(),显示下一个或上一个图像链接,该链接具有相同的文章父。

用法:

adjacent_i**ge_link( bool $prev = true, string|int[] $size = ‘thumbnail’, bool $text = false )

描述:

从$post全局变量中检索当前附件对象。

参数:

$prev

(bool) (可选) 是否显示下一个(false)或上一个(true)链接。

默认值: true

$size

(string|int[]) (可选) 图像的大小。接受任何注册的图像大小名称,或以像素为单位的宽度和高度值数组(按此顺序)。

默认值: ‘thumbnail’

$text

(bool) (可选) 链接文本。

默认值: false

来源:

文件: wp-includes/media.php

function adjacent_i**ge_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’ => ‘i**ge’,

‘order’ => ‘ASC’,

‘orderby’ => ‘menu_order ID’,

)

)

);

foreach ( $attachments as $k => $attachment ) {

if ( (int) $attachment->ID === (int) $post->ID ) {

break;

}

}

$output = ”;

$attachment_id = 0;

if ( $attachments ) {

$k = $prev ? $k – 1 : $k + 1;

if ( isset( $attachments[ $k ] ) ) {

$attachment_id = $attachments[ $k ]->ID;

$attr = array( ‘alt’ => get_the_title( $attachment_id ) );

$output = wp_get_attachment_link( $attachment_id, $size, true, false, $text, $attr );

}

}

$adjacent = $prev ? ‘previous’ : ‘next’;

/**

* Filters the adjacent i**ge link.

*

* The dyn**ic portion of the hook n**e, `$adjacent`, refers to the type of adjacency,

* either ‘next’, or ‘previous’.

*

* @since 3.5.0

*

* @par** string $output Adjacent i**ge HTML **rkup.

* @par** int $attachment_id Attachment ID

* @par** string|int[] $size Requested i**ge size. Can be any registered i**ge size n**e, or

* an array of width and height values in pixels (in that order).

* @par** string $text Link text.

*/

echo apply_filters( “{$adjacent}_i**ge_link”, $output, $attachment_id, $size, $text );

}

更新日志:

WordPress开发函数adjacent_image_link() (https://www.wpzt.net/) WordPress开发教程 第1张

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容