如何使用“下一步”和“上一步”按钮更改页码?

时间:2017-02-25 作者:Tarik Elmoktadi

如何更改此分页:pagination with numbers

看起来像这样:

next and back button

请帮助我,我的页面代码是:

if($max_page > 1 || intval($pagenavi_options[\'always_show\']) == 1) {
    $pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), $pagenavi_options[\'pages_text\']);
    $pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text);

    echo \'<div class="page-nav td-pb-padding-side">\';   
    previous_posts_link($pagenavi_options[\'prev_text\']);
    if ($start_page >= 2 && $pages_to_show < $max_page) {
        $first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options[\'first_text\']);
        echo \'<a href="\'.esc_url(get_pagenum_link()).\'" class="first" title="\'.$first_page_text.\'">\'.$first_page_text.\'</a>\';
        if(!empty($pagenavi_options[\'dotleft_text\']) && ($start_page > 2)) {
            echo \'<span class="extend">\'.$pagenavi_options[\'dotleft_text\'].\'</span>\';
        }
    }
    /*
    if($larger_page_to_show > 0 && $larger_start_page_start > 0 && $larger_start_page_end <= $max_page) {
        for($i = $larger_start_page_start; $i < $larger_start_page_end; $i+=$larger_page_multiple) {
            $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options[\'page_text\']);
            echo \'<a href="\'.esc_url(get_pagenum_link($i)).\'" class="page" title="\'.$page_text.\'">\'.$page_text.\'</a>\';
        }
        echo \'<span class="extend">\'.$pagenavi_options[\'dotleft_text\'].\'</span>\';
    }*/

    for($i = $start_page; $i  <= $end_page; $i++) {
        if($i == $paged) {
            $current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options[\'current_text\']);
            echo \'<span class="current">\'.$current_page_text.\'</span>\';
        } else {
            $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options[\'page_text\']);
            echo \'<a href="\'.esc_url(get_pagenum_link($i)).\'" class="page" title="\'.$page_text.\'">\'.$page_text.\'</a>\';
        }
    }

    /*
    if($larger_page_to_show > 0 && $larger_end_page_start < $max_page) {
        echo \'<span class="extend">\'.$pagenavi_options[\'dotright_text\'].\'</span>\';
       for($i = $larger_end_page_start; $i <= $larger_end_page_end; $i+=$larger_page_multiple) {
           $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options[\'page_text\']);
           echo \'<a href="\'.esc_url(get_pagenum_link($i)).\'" class="page" title="\'.$page_text.\'">\'.$page_text.\'</a>\';
       }
    }*/
    if ($end_page < $max_page) {
        if(!empty($pagenavi_options[\'dotright_text\']) && ($end_page + 1 < $max_page)) {
            echo \'<span class="extend">\'.$pagenavi_options[\'dotright_text\'].\'</span>\';
        }

        $last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options[\'last_text\']);
        echo \'<a href="\'.esc_url(get_pagenum_link($max_page)).\'" class="last" title="\'.$last_page_text.\'">\'.$last_page_text.\'</a>\';
    }
    next_posts_link($pagenavi_options[\'next_text\'], $max_page);
    if(!empty($pages_text)) {
        echo \'<span class="pages">\'.$pages_text.\'</span>\';
    }
    echo \'</div>\';

}

1 个回复
SO网友:Morshed Maruf

the_posts_pagination(array(
        prev_text => \'PREV\',
        next_text => \'NEXT\',
        screen_reader_text => \' \' 
        ));
对于分页,您应该试试这个。希望这对你有帮助。

相关推荐

Count posts for pagination

我正在为一个网站分页<;上一页(页码)下一页>很简单,已经完成。但是现在我需要添加一个选择器来直接转到页面(例如:转到第7页),要这样做,我需要知道有多少页面,为此我需要计算在查询中找到了多少帖子。问题是这个网站有太多的帖子(>13.000),查询所有帖子都会减慢页面加载速度,这就像。。。10秒后页面才能加载。显然,这是不可接受的。分页解决了这个问题,因为一次只加载50或100篇文章,但我无法将它们全部计算在内。我可以在不加载的情况下统计某个查询中的帖子吗?或者我可以通过其他方式获得页数吗