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();
}
正如马库斯所说,该功能has_next_page()
不适用于较新的 wp 版本,因此您可以简单地在 if 语句中使用get_previous_posts_link()
and 。get_next_posts_link()
虽然像许多人一样,我使用 Lester Chan.right 的 pagenavi 插件http://lesterchan.net/wordpress/readme/wp-pagenavi.html