WordPress函数:get_adjacent_post(获取相邻文章)

Description【描述】

Retrieve adjacent post.【检索相邻的文章】

Can either be next or previous post.【可以是上一篇或下一篇】

Usage【用法】

&lt;?php <a href="https://www.wpdaxue.com/tag/get_adjacent_post" title="查看与【get_adjacent_post】相关的文章" target="_blank" rel="noopener">get_adjacent_post</a>( $in_same_cat, $excluded_categories, $previous ) ?&gt;

Parameters【参数】

$in_same_cat
(boolean) (optional) Whether post should be in same category.【(布尔值)(可选)文章是否在同一分类】

Default: false【默认:false】
$excluded_categories
(string) (optional) Excluded categories IDs.【(字符串)(可选)排除分类的ID】

Default: ”【默认:”】
$previous
(boolean) (optional) Whether to retrieve previous post.【(布尔值)(可选)是否检索之前的文章】

Default: true【默认:true】

Return Values【返回值】

  • Post object if successful. 【如果成功,返回文章对象】
  • Null if global $post is not set. 【如果全局的 $post 没有设置,返回空值】
  • Empty string if no corresponding post exists. 【如果不存在符合条件的文章,返回空字符串】

Examples【例子】

Notes【注释】

  • Uses global: (object) $post 【使用全局:(对象)$post
  • Uses global: (object) $wpdb 【使用全局:(对象)$wpdb

Filters【过滤器】

$adjacent is either ‘previous’ or ‘next’.【$adjacent 是“上一篇”或“下一篇”】

  • "get_{$adjacent}_post_join":

    $join, $in_same_cat, $excluded_categories

  • "get_{$adjacent}_post_where":

    $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories

  • "get_{$adjacent}_post_sort":

    "ORDER BY p.post_date $order LIMIT 1"

Change Log【更改记录】

Since: 2.5.0 【从 2.5.0 开始】

Source File【源文件】

get_adjacent_post() is located in wp-includes/link-template.php.【get_adjacent_post()函数在wp-includes/link-template.php 文件中】

参考资料:http://codex.wordpress.org/Function_Reference/get_adjacent_post

来源:

https://www.wpdaxue.com/wordpress-function-get_adjacent_post.html

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?