是否始终在wp_link_ages中显示下一个和上一个按钮?

时间:2016-08-17 作者:helloMundo

如何让wp\\u link\\u pages()在多页文章的开头以及多页文章的结尾显示“下一页”和“上一页”按钮。当前,只有当它是第一页时,才显示Next,而在该页的末尾显示Previous。

2 个回复
SO网友:Levi Dulstein

我刚刚遇到了同样的问题,下面是我的解决方案。我使用globals获取当前页面和总页面数:

/* first i\'m looking into $multipage global to check 
if the post actually has pages */
global $multipage;

if ( $multipage === 1 ) {
    global $page; // this is current page number
    global $numpages; // this is total page count

    // display disabled left arrow on page 1
    if ( 1 === $page ) :
    ?>
        <span class="pagination__arrow pagination__arrow--prev pagination__arrow--disabled">< Previous</span>
        <span class="pagination__separator"> | </span>
    <?php 
    endif;

    // standard wp pagination
    wp_link_pages( [
        \'next_or_number\'   => \'next\',
        \'before\'           => \'\',
        \'previouspagelink\' => \'<span class="pagination__arrow pagination__arrow--prev">< Previous</span>\',
        \'nextpagelink\'     => \'<span class="pagination__arrow pagination__arrow--next">Next ></span>\',
        \'separator\'        => \'<span class="pagination__separator">|</span>\',
    ] );

    // display disabled right arrow on last page
    if ( $page === $numpages ) :
    ?>
        <span class="pagination__separator"> | </span>
        <span class="pagination__arrow pagination__arrow--next pagination__arrow--disabled">Next ></span>
    <?php
    endif;

}

SO网友:Joseph Seyi Taiwo

你可以看看这个wp_link_pages Function

相关推荐

change pagination url

目前,我的分页页面URL为:http://www.example.com/category_name/page/2但我需要将此URL结构更改为:http://www.example.com/category_name/?page=2等有什么解决方案吗?