您现在的位置是:首页 > 网站制作 > WordpressWordpress
WordPress获取相邻文章函数:get_adjacent_post
杰帅2023-02-02【Wordpress】人已围观
简介WordPress函数get_adjacent_post用于获取相邻文章的信息,包括文章ID、文章发表时间、文章标题、文章别名、文章内容和文章摘要等。
get_adjacent_post( boolean $in_same_term = false, array $excluded_terms = '', boolean $previous = true, string $taxonomy = 'category' )
函数参数
$in_same_term
布尔值,默认值:false
是否返回同分类下的相邻文章,默认不区分分类。
$excluded_terms
数组,默认为空
提供要排除的分类ID
$previous
布尔值,默认值:true
如果为false,则返回下一篇文章的信息,默认返回上一篇文章的信息。
$taxonomy
字符串值,默认值:category
提供自定义分类法的名称
函数返回值
WP_Post Object ( [ID] => 215 [post_author] => 1 [post_date] => 2014-07-24 14:01:55 [post_date_gmt] => 2014-07-24 06:01:55 [post_content] => 文章内容 [post_title] => 文章标题 [post_excerpt] => 文章摘要 [post_status] => publish [comment_status] => open [ping_status] => closed [post_password] => [post_name] => 文章别名 [to_ping] => [pinged] => [post_modified] => 2015-06-22 14:38:47 [post_modified_gmt] => 2015-06-22 06:38:47 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/215.html [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw )
函数使用示例
<?php $prev_post = get_adjacent_post( true ); if ( is_a( $prev_post, 'WP_Post' ) ) { echo '<a href="' . get_permalink( $prev_post->ID ) . '">' . $prev_post->post_title . '</a>'; } ?>
扩展阅读
get_adjacent_post()函数位于:wp-includes/link-template.php
相关函数:
Tags:get_adjacent_post wordpress获取上一条 wordpress获取xia'yi'tiao
很赞哦! ()
相关文章
随机图文
如何将WordPress文章迁移到Shopify:使用WP All Export插件的完整指南
如果您正在将WordPress网站迁移到Shopify,并希望将文章内容一起迁移,WP All Export插件是一个理想的解决方案。通过这款插件,您可以轻松导出WordPress中的文章,并将其转换为适合Shopify的CSV格式。WordPress 页面模板(Page Template)下拉列表不显示的原因及解决方法
WordPress 的自定义页面模板是一个非常强大好用的功能,使用它新建一些静态页面(Page),添加上一些数据调用的函数,再在网页上做一个导航连接到对应的页面就可以实现很多自定义的功wp_reset_postdata 和 wp_reset_query 的作用与区别
什么时候使用wp_reset_query,什么时候用wp_reset_postdata?wordpress 上传的图片不显示的问题 base64,data:image/gif