SpiraL
5/15/2018 - 11:52 AM

Pagination

Comments Template:

<div class="paginate-com">
<?php paginate_comments_links( array ('prev-text' => '&lsaquo; Previuos', 'next-text' => 'Next &rsaquo;')); ?>
</div>

CSS:

/* comment pagination */

.paginate-com {
        margin: 10px 0 20px 0;
        padding: 5px 1px 5px;
        text-align: center;
        border: 1px solid #eaeaea;
    }
.paginate-com a {
    padding: 3px 6px 4px 6px;
    margin: 3px;
    text-decoration: none;
    border: 1px solid #aac;
    color: #666;
    background-color: inherit;
}
.paginate-com a:hover {
    border: 1px solid #444;
    color: #444;
    background-color: #eee;
}
.paginate-com .current {
    padding: 3px 6px 4px 6px;
    margin: 3px;
    font-weight: bold;
    border: 1px solid #666;
}

Affichage personnalisé de la pagination

$query_recipe correspond à la boucle custom WP_Query


  $args_query_recipe = [
  'post_type' => 'projet',
  'posts_per_page' => 8,
  // 'category_name'    => 'projet',
  // 'category_name' =>
  ];
  $query_recipe = new WP_Query($args_query_recipe);
  if ($query_recipe->have_posts()):
  while($query_recipe->have_posts()):
  $query_recipe->the_post();

Mettre le code entre endwhile et endif!!!


    $links = paginate_links( array(
    'prev_next'          => false,
    'type'               => 'array',
    'total'              => $query_recipe->max_num_pages,
  ) );
  
  if ( $links ) :
  
      echo '<div class="page-numbers">';
  

      if ( $prev_posts_link =  previous_posts_link('< articles précédents', $query_recipe->max_num_pages) ) :
          echo '<div class="prev-list-item">';
          echo $prev_posts_link;
          echo '</div>';
      endif;
  
      echo '<div>';
      echo join($links );
      echo '</div>';
  

      if ( $next_posts_link =  next_posts_link('articles suivants >', $query_recipe->max_num_pages) ) :
          echo '<div class="next-list-item">';
          echo $next_posts_link;
          echo '<div>';
      endif;
      echo '</div>';
  endif;

Autre Méthode de pagination


 $argspag = array(
    'base'               => '%_%',
    'format'             => '?paged=%#%',
    'total'              => $query_recipe->max_num_pages,
    'current'            => 0,
    'show_all'           => false,
    'end_size'           => 1,
    'mid_size'           => 2,
    'prev_next'          => false,
    'prev_text'          =>  '',
    'next_text'          =>  '',
    'type'               => 'list',
    'add_args'           => false,
    'add_fragment'       => '',
    'before_page_number' => '',
    'after_page_number'  => ''
);


  <?php previous_posts_link('< articles précédents', $query_recipe->max_num_pages);?>



   <?php echo paginate_links($argspag);?>



  <?php  next_posts_link('articles suivants >', $query_recipe->max_num_pages);?>


A tester!!!

    <div class="pagination_wrapper texte_droit">
      <!-- <?php
      // $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

      $data= new WP_Query(array(
          'post_type'=>'post', // your post type name
          'posts_per_page' => 3, // post per page
          // 'paged' => $paged,
      ));

      if($data->have_posts()) :
          while($data->have_posts())  : $data->the_post();
                  // Your code
          endwhile;

          $total_pages = $data->max_num_pages;

          if ($total_pages > 1){

              $current_page = max(1, get_query_var('paged'));

              echo paginate_links(array(
                  'base' => get_pagenum_link(1) . '%_%',
                  'format' => '/page/%#%',
                  'current' => $current_page,
                  'total' => $total_pages,
                  'prev_text'    => __('Articles précédents'),
                  'next_text'    => __('Articles suivants'),
              ));
          }
          ?>
      <?php else :?>
      <h3><?php _e('404 Error&#58; Not Found', ''); ?></h3>
      <?php endif; ?>
      <?php wp_reset_postdata();?> -->


    </div>

A tester aussi

          $total_pages = $query_recipe->max_num_pages;

  if ($total_pages > 1){

      $current_page = max(1, get_query_var('paged'));?>


     <?php echo paginate_links(array(
          'base' => get_pagenum_link(1) . '%_%',
          'format' => '/page/%#%',
          'current' => $current_page,
          'total' => $total_pages,
          'prev_text'    => __('Articles précédents'),
          'next_text'    => __('Articles suivants'),
      ));