get_previous_post()
get_previous_post( bool $in_same_term = false, array|string $excluded_terms = ”, string $taxonomy = ‘category’ )
检索与当前文章相邻的上一篇文章。
Retrieves the previous post that is adjacent to the current post.
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$in_same_term | (bool) | 可选 | post是否应该在同一个分类术语中。 |
$excluded_terms | (array | string) | 可选 | 排除的术语ID的数组或逗号分隔列表。 |
$taxonomy | (string) | 可选 | 分类法,如果$in_相同的术语是真的。 |
返回(Return)
(null|string|WP_Post)Post对象(null|string|WP_Post)。如果未设置全局$post,则为空。如果不存在对应的post,则为空string。
源码(Source)
/** * Retrieve previous post that is adjacent to current post. * * @since 1.5.0 * * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. */ function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { return get_adjacent_post( $in_same_term, $excluded_terms, true, $taxonomy ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
1.5.0 | wp-includes/link-template.php:1667 | 1 function | 1 function |
笔记(Notes)
例子
get_previous_post() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_previous_post/