WordPress获取最早或最近文章函数:get_boundary_post
文 / @WordPress主题
WordPress函数get_boundary_post用于获取最早或最近发表的一篇文章,在实际应用中使用得非常少。
get_boundary_post( boolean $in_same_term = false, string $excluded_terms = '', boolean $start = true, string $taxonomy = 'category' )
函数参数
$in_same_cat
布尔值,默认值:false
是否返回同分类下的文章,默认不区分分类。
$excluded_categories
字符串值,默认为空
提供排除分类的ID,多个ID用半角逗号分隔。
$start
布尔值,默认值:true
- true:返回最早的文章;
- false:返回最近的文章;
$taxonomy
字符串值,默认值:category
提供自定义分类法的名称
函数返回值
Array ( [0] => WP_Post Object ( [ID] => 36 [post_author] => 1 [post_date] => 2014-07-06 16:45:17 [post_date_gmt] => 2014-07-06 08:45:17 [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-26 19:59:04 [post_modified_gmt] => 2015-06-26 11:59:04 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/36.html [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw ) )
函数使用示例
<?php $first= get_boundary_post(); if (!empty($first)) { foreach ($first as $post) { echo '<a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a>'; } } ?>
扩展阅读
get_boundary_post()函数位于:wp-includes/link-template.php
相关函数:
- get_next_post()
- get_previous_post()

相关文章
-
搭建一个WordPress网站需要多少成本 2023-11-06 00:09:51
-
Symlink介绍(附:如何使用Symlink进行WordPress开发) 2023-11-05 23:38:32
-
让WordPress实现数据库同步的插件:HyperDB 2023-10-24 23:40:49
-
allegro电商平台值得做吗(附:2023年Allegro注册流程指南) 2023-10-08 21:53:39
-
印度跨境电商平台有哪些(附:印度跨境电商做什么产品好) 2023-10-08 21:34:23
-
跨境电商必看的几大海外二手电商平台 2023-10-08 18:04:42
-
WordPress同城互联网产品解决方案:UBASE 2023-10-03 16:40:39
-
WordPress网站的安全插件:wordfence 2023-09-14 09:25:18
-
WordPress 6.3 支持在手动更新插件和主题失败后回滚旧版本 2023-08-28 16:58:45
-
WordPress 6.3版本(2023年8月)性能提升了哪些? 2023-08-28 16:56:02