Pagination list user problem number of pages

Question

I have to do a pagination that retrieves a list of contributors from the site, there are three (no problem). With docs, tutorials … My pagination works. I set the number of contributors to two per page (no problem). But I don’t understand why I have a continuation of page which goes up to 7. When I click on this 7th page for example I arrive on page with an empty list (normal). Normally it should stop at three pages maximum. I was told to indicate the number of post / page but by searching the documents and tutorial I do not understand.

    $total_users = count_users();
    $total_users = $total_users['total_users'];
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    $number = 1;
    $offset = $paged ? ($paged - 1) * $number : 0;
    $total_pages = floor($total_users / $number);

    $contributor_member = array(
        'role' => 'Contributor',
        'orderby' => 'user_nicename',
        'order' => 'ASC',
        'offset' => $offset,
        'number' => $number,
    );
    ob_start();
    $authors = get_users($contributor_member);
    foreach ($authors as $users):
        echo '<div class="column-member">';
        echo '<div class="info-member">';
        echo '<span class="comite-description-name"><a href=' . get_author_posts_url($users->ID) . '>' . $users->display_name . '</a></span>';
        echo '<span class="comite-description">' . $users->institution_rattachementUser . '</span>';
        echo '<span class="comite-description">' . $users->fonctionUser . '</span>';
        echo '</div>';
        echo '<div class="button-member">';
        echo '<a href=' . get_author_posts_url($users->ID) . '>En savoir plus</a>';
        echo '</div>';
        echo '</div>';
        echo '<hr class="separator-member">';
    endforeach;
    if($total_users > $number){
      echo '<div class="pagination-list">';          
          echo paginate_links (array(
             'total' => $total_pages,
             'prev_next' => false,
             'base' => get_pagenum_link(1) . '%_%',  
             'format' => 'page/%#%/', 
             'show_all' => true,
          ));
      echo '</div>';
    }
    $short_list = ob_get_clean();;
    return $short_list;
0
Dim 8 months 2020-12-04T07:25:42-05:00 0 Answers 5 views 0

Leave an answer

Browse
Browse