get_adjacent_post_rel_link
函数
get_adjacent_post_rel_link ( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' )
- 参数
-
-
(string)
$title
Optional. Link title format. Default ‘%title’.- Required: 否
- Default: ‘%title’
-
(bool)
$in_same_term
Optional. Whether link should be in a same taxonomy term. Default false.- Required: 否
- Default: false
-
(int[]|string)
$excluded_terms
Optional. Array or comma-separated list of excluded term IDs. Default empty.- Required: 否
- Default: (empty)
-
(bool)
$previous
Optional. Whether to display link to previous or next post. Default true.- Required: 否
- Default: true
-
(string)
$taxonomy
Optional. Taxonomy, if $in_same_term is true. Default ‘category’.- Required: 否
- Default: ‘category’
-
(string)
- 返回值
-
- (string|void) The adjacent post relational link URL.
- 定义位置
-
-
wp-includes/link-template.php
, line 2010
-
wp-includes/link-template.php
- 引入
- 2.8.0
- 弃用
- –
检索相邻文章的关系链接。
可以是下一个或上一个文章的关系链接。
function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { $post = get_post(); if ( $previous && is_attachment() && $post ) { $post = get_post( $post->post_parent ); } else { $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); } if ( empty( $post ) ) { return; } $post_title = the_title_attribute( array( 'echo' => false, 'post' => $post, ) ); if ( empty( $post_title ) ) { $post_title = $previous ? __( 'Previous Post' ) : __( 'Next Post' ); } $date = mysql2date( get_option( 'date_format' ), $post->post_date ); $title = str_replace( '%title', $post_title, $title ); $title = str_replace( '%date', $date, $title ); $link = $previous ? "n"; $adjacent = $previous ? 'previous' : 'next'; /** * Filters the adjacent post relational link. * * The dynamic portion of the hook name, `$adjacent`, refers to the type * of adjacency, 'next' or 'previous'. * * Possible hook names include: * * - `next_post_rel_link` * - `previous_post_rel_link` * * @since 2.8.0 * * @param string $link The relational link. */ return apply_filters( "{$adjacent}_post_rel_link", $link ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。