next_post_link()
函数是常用的Wordpress函数之一,用于显示当前文章相邻的下一篇文章链接,上一篇、下一篇文章几乎是当下网站都会添加的文章页面元素,据说是有利于SEO优化。本篇内容博客吧分享获取下一篇文章函数next_post_link()
使用教程和方法。
1 2 3 | <?php next_post_link( string $format = '%link »', string $link = '%title', bool $in_same_term = false, int[]|string $excluded_terms = '', string $taxonomy = 'category' ) ?> |
---|
如果存在下一篇文章,则带箭头的标题超链接的形式显示下一篇文章,如果没有下一篇文章,则不显示任何内容。
1 | <?php next_post_link();?> |
---|
去掉默认的箭头
1 | <?php next_post_link('%link','%title');?> |
---|
去掉默认的箭头,不使用标题文字,加粗
1 | <?php next_post_link('<strong>%link</strong>','下一篇');?> |
---|
只显示相同分类的下一篇文章
1 | <?php next_post_link('%link','%title',true,'','category');?> |
---|
排除分类ID为5的文章
1 | <?php next_post_link('%link','%title','','5');?> |
---|
排除分类ID为5,6,7的文章
1 | <?php next_post_link('%link','%title','',array(5,6,7));?> |
---|
函数位置:wp-includes/link-template.php
官方文档:https://developer.wordpress.org/reference/functions/next_post_link/