skip to Main Content

my pagination code:

function tevent_pagination() {

// Allowed html 

$allowed_html = [
    "span" => [
        "class" => []
    ],
    "a" => [
        "class" => [],
        "href" => []
    ]
];

// What should be before the page number
$args = [
    'before_page_number' => '<span>',
    'after_page_number' => '</span>'
];
// Printing the pagination
printf("<nav class='pagination'>%s</nav>", wp_kses( paginate_links( $args ), $allowed_html ));}

pagination links are correctly displayed, even the content is perfectly display which I click pagination links. but when I click on links the .current class is not updating. I have tried many things but still this issue is not resolving.

2

Answers


  1. Chosen as BEST ANSWER

    This issue was resolved by writing wp_reset_query() at the top of the function.


  2. You are not passing current page on the args.

    global $wp_query;
    
    $big = 999999999; // need an unlikely integer
    $args = [
        'before_page_number' => '<span>',
        'after_page_number' => '</span>',
        'format'  => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total'   => $wp_query->max_num_pages
    ];
    echo paginate_links($args);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search