描述:
调用同分类下一篇文章
用法:
<?php get_next_post( $in_same_term, $excluded_terms, $taxonomy ) ?>
参数:
$in_same_term
(boolean) (可选) 是否要显示同分类下的文章
默认值: false
$excluded_terms
(string) (可选) 要排除的分类ID
默认值:
$taxonomy
(string) (可选) 分类法,如果$in_same_term为true。
默认值: 'category'
示例:
<?php
$next_post = get_next_post();
if ( is_a( $next_post , 'WP_Post' ) ) { ?>
<a href="<?php echo get_permalink( $next_post->ID ); ?>"><?php echo get_the_title( $next_post->ID ); ?></a>
<?php } ?>
源文件:
/**
* Retrieve next 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_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
return get_adjacent_post( $in_same_term, $excluded_terms, false, $taxonomy );
}