简体   繁体   English

WordPress的自定义分页“下一页”不起作用

[英]Wordpress custom pagination “next page” not working

I found this custom wordpress pagination somewhere and tried using it. 我在某个地方找到了这种自定义的wordpress分页,并尝试使用它。 The pagination and the "view all" functionality works fine but the problem is with the "next" and "previous" function. 分页和“查看全部”功能工作正常,但问题出在“下一个”和“上一个”功能上。 When click the "next button" it skips to the last page. 单击“下一个按钮”时,它将跳至最后一页。 Can you please help me debug this code? 您能帮我调试此代码吗? I am not really familiar with php, it's actually my first time integrating to wordpress. 我对php并不是很熟悉,这实际上是我第一次集成到wordpress中。 Thank you! 谢谢!

 function numeric_pagination ($pageCount = 9, $query = null) {
        if ($query == null) {
            global $wp_query;
            $query = $wp_query;
        }
        if ($query->max_num_pages <= 1) {
            return;
        }
        $pageStart = 1;
        $paged = $query->query_vars['paged'];
        // set current page if on the first page
        if ($paged == null) {
            $paged = 1;
        }
        // work out if page start is halfway through the current visible pages and if so move it accordingly
        if ($paged > floor($pageCount / 2)) {
            $pageStart = $paged - floor($pageCount / 2);
        }
        if ($pageStart < 1) {
            $pageStart = 1;
        }
        // make sure page start is
        if ($pageStart + $pageCount > $query->max_num_pages) {
            $pageCount = $query->max_num_pages - $pageStart;
        }
    ?>

    <div id="pagination">
        <?php
        if ($paged != 1) {
        ?>

        <a href="<?php echo get_pagenum_link(1); ?>" class="numbered page-number-first"><span>&lsaquo;&lsaquo; <?php _e('Previous Page', 'rhinoplasty'); ?></span></a>

        <?php
        }
        if ($pageStart > 1) {
            //echo 'previous';
        }
        for ($p = $pageStart; $p <= $pageStart + $pageCount; $p ++) {
            if ($p == $paged) {
        ?>

        <span class="numbered page-number-<?php echo $p; ?> current-numeric-page"><?php echo $p; ?></span>

        <?php } else { ?>

        <a href="<?php echo get_pagenum_link($p); ?>" class="numbered page-number-<?php echo $p; ?>"><span><?php echo $p; ?></span></a>

        <?php
            }
        }
        if ($pageStart + $pageCount < $query->max_num_pages) {
            //echo "last";
        }
        if ($paged != $query->max_num_pages) {
        ?>

        <a href="<?php echo get_pagenum_link($query->max_num_pages); ?>" class="numbered page-number-last"><span><?php _e('Next Page', 'rhinoplasty'); ?> &rsaquo;&rsaquo;</span></a>
        <?php } ?>
        <?php if(!$_GET['viewall']){ ?>
        <a href="<?php  echo add_query_arg( array( 'viewall' => "true" ), get_pagenum_link(1) ); ?>">View All</a>
        <?php } ?>
    </div>

    <?php
     }
    if (isset($_GET['viewall']))
    {
        function view_allposts( $query ) {
            $query->set( 'posts_per_page', -1 );
        }
        add_action( 'pre_get_posts', 'view_allposts' );
    }

尝试将代码行更改为:

<a href="<?php echo get_pagenum_link($paged+1); ?>" class="numbered page-number-last"><span><?php _e('Next Page', 'rhinoplasty'); ?> &rsaquo;&rsaquo;</span></a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM