get_next_post()函數(shù)用于獲取下一篇文章的信息,包括:文章內(nèi)容、摘要、狀態(tài)、標(biāo)題、作者、發(fā)布時(shí)間等。
語(yǔ)法結(jié)構(gòu)
get_next_post( boolean $in_same_term = false, string $excluded_terms = '', string $taxonomy = 'category' )
參數(shù)
$in_same_term 布爾值,默認(rèn)值:false,是否只返回相同分類下的文章
$excluded_terms 字符串值,默認(rèn)為空,需要排除的分類ID,用半角逗號(hào)分隔多個(gè)ID
$taxonomy 字符串值,默認(rèn)值:category,自定義分類法的名稱
實(shí)例
<?php
$next_post = get_next_post();
if (!empty( $next_post )): ?>
<a href="<?php echo get_permalink( $next_post->ID ); ?>"><?php echo $next_post->post_title; ?></a>
<?php endif; ?>