Wordpress有没有类似的功能或者什么东西?我需要一种方法来检查是否有任何页面链接(旧文章 | 新文章)需要显示。
最好的问候,
Wordpress有没有类似的功能或者什么东西?我需要一种方法来检查是否有任何页面链接(旧文章 | 新文章)需要显示。
最好的问候,
如果你查看new_posts_link函数,你会看到$max_page和$paged变量。
如果$pages大于1,则会有一个上一页链接。
如果它小于$max_page,则会有一个下一页链接。
因此,您可以执行以下功能:
# Will return true if there is a next page
function has_next_page() {
global $paged, $max_page;
return $paged < $max_page;
}
# Will return true if there is a previous page
function has_previous_page() {
global $paged;
return $paged > 1;
}
# Will return true if there is more than one page (either before or after).
function has_pagination() {
return has_next_page() or has_previous_page();
}
正如Marcus所说,函数has_next_page()
在较新的wp版本中不起作用,因此您可以在if语句中简单地使用get_previous_posts_link()
和get_next_posts_link()
。
虽然像许多人一样,我使用Lester Chan的pagenavi插件。http://lesterchan.net/wordpress/readme/wp-pagenavi.html