国产三级农村妇女在线,国产精品毛片a∨一区二区三区,国产乱子伦视频大全,国产精品色拉拉,国产欧美日韩一区二区三区,

首頁 > 技術(shù) > cms教程

WordPress開發(fā)函數(shù)adjacent_image_link()

cms教程 2022-10-26 09:23:43

WordPress開發(fā)函數(shù)adjacent_image_link(),顯示下一個(gè)或上一個(gè)圖像鏈接,該鏈接具有相同的文章父。

用法:

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

描述:

從$post全局變量中檢索當(dāng)前附件對(duì)象。

參數(shù):

$prev

(bool) (可選) 是否顯示下一個(gè)(false)或上一個(gè)(true)鏈接。

默認(rèn)值: true

$size

(string|int[]) (可選) 圖像的大小。接受任何注冊(cè)的圖像大小名稱,或以像素為單位的寬度和高度值數(shù)組(按此順序)。

默認(rèn)值: 'thumbnail'

$text

(bool) (可選) 鏈接文本。

默認(rèn)值: false

來源:

文件: 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 ( (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 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|int[] $size Requested image size. Can be any registered image size name, or

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

* @param string $text Link text.

*/

echo apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text );

}

更新日志:

WordPress開發(fā)函數(shù)adjacent_image_link() (https://www.wpzt.net/) WordPress開發(fā)教程 第1張

TAg

加載中~

本網(wǎng)站LOGO受版權(quán)及商標(biāo)保護(hù),版權(quán)登記號(hào):國作登字-2022-F-10126915,未經(jīng)湖南木星科技官方許可,嚴(yán)禁使用。
Copyright ? 2012-2022 湖南木星科技有限公司(木星網(wǎng))版權(quán)所有
轉(zhuǎn)載內(nèi)容版權(quán)歸作者及來源網(wǎng)站所有,本站原創(chuàng)內(nèi)容轉(zhuǎn)載請(qǐng)注明來源,商業(yè)媒體及紙媒請(qǐng)先聯(lián)系:aishangyiwan@126.com

工信部備案號(hào):湘ICP備19012813號(hào)-5