我为Wordpress做了一个简单的“帖子页面”导航,我无法找到改变next_posts_link()和previous_posts_link()行为的方法,这样无论显示什么页面,按钮始终可见.
这是不同状态的菜单:
我知道没有在第一页/最后一页上显示’上一页’/’下一页’按钮是这个Wordpress功能的预期,但是我需要覆盖这种行为,这样就会显示一个灰色的上一页/下一页文本.分别是第一页/最后一页.
任何帮助将非常感谢我如何实现这一点.谢谢
这是代码:
<?php
function pagination_nav() {
global $wp_query;
$total_pages = $wp_query->max_num_pages;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
?>
<nav class="pagination" role="navigation">
<div class="nav-previous">← <?php previous_posts_link( 'Previous Page ' ); ?></div>
<div class="nav-position">Page <?php echo $paged ?> of <?php echo $total_pages ?></div>
<div class="nav-next"><?php next_posts_link( 'Next Page' ); ?> →</div>
</nav>
<?php } ?>
最佳答案 工作解决方案(但可能更好!):
<?php
function pagination_nav() {
global $wp_query;
$total_pages = $wp_query->max_num_pages;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
?>
<nav class="pagination" role="navigation">
<div class="nav-previous">
<?php
if ($paged == 1) {
echo '<div class="nav-previous-empty">Previous Page</div>';
} else {
previous_posts_link( 'Previous Page' );
}
?>
</div>
<div class="nav-position">Page <?php echo $paged ?> of <?php echo $total_pages ?></div>
<div class="nav-next">
<?php
if ($paged == $total_pages) {
echo '<div class="nav-next-empty">Next Page</div>';
} else {
next_posts_link( 'Next Page' );
}
?>
</div>
</nav>
<?php } ?>