php – when clicking the next button of pagination, not appearing the contents of next page in Word Press-ThrowExceptions

Exception or error:

when I clicking the pagination to go to the next page, there are still the contents of first page appearing, never show the contents of second page…

after clicking, the URL of the page contained “page/2/” at last. so seems like the page is right. but contents is not right.
(please just ignore those japanese letters)

please tell me what’s the problem.

functions.php

//Pagenation
function pagination($pages = '', $range = 2)
{
     $showitems = ($range * 2)+1;//表示するページ数(5ページを表示)

     global $paged;//現在のページ値
     if(empty($paged)) $paged = 1;//デフォルトのページ

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;//全ページ数を取得
         if(!$pages)//全ページ数が空の場合は、1とする
         {
             $pages = 1;
         }
     }

     if(1 != $pages)//全ページが1でない場合はページネーションを表示する
     {
         echo "<div class=\"pagenation\">\n";
         echo "<ul>\n";
         //Prev:現在のページ値が1より大きい場合は表示
         if($paged > 1) echo "<li class=\"prev\"><a href='".get_pagenum_link($paged - 1)."'>Prev</a></li>\n";

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                //三項演算子での条件分岐
                echo ($paged == $i)? "<li class=\"active\">".$i."</li>\n":"<li><a href='".get_pagenum_link($i)."'>".$i."</a></li>\n";
             }
         }
        //Next:総ページ数より現在のページ値が小さい場合は表示
        if ($paged < $pages) echo "<li class=\"next\"><a href=\"".get_pagenum_link($paged + 1)."\">Next</a></li>\n";
        echo "</ul>\n";
        echo "</div>\n";
     }
}

archive.php

        <?php
//Pagenation 
if (function_exists("pagination")) {
    pagination($additional_loop->max_num_pages);
}
?>
How to solve:

please use WordPress default pagination function to show on archive.php

<?php
global $wp_query;

$big = 999999999; // need an unlikely integer
$translated = __( 'Page', 'mytextdomain' ); // Supply translatable string

echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $wp_query->max_num_pages,
        'before_page_number' => '<span class="screen-reader-text">'.$translated.' </span>'
) );
?>

Leave a Reply

Your email address will not be published. Required fields are marked *