cipher87

Pagination

Oct 21st, 2020
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.08 KB | None | 0 0
  1. /**
  2.  * @link https://kriesi.at/support/topic/pagination-show-last-page/#post-1254266
  3.  */
  4. function enfold_pagination_output($output, $paged, $pages, $wrapper, $query_arg) {
  5.     $output = '';
  6.     $prev = $paged - 1;
  7.     $next = $paged + 1;
  8.     $range = 2;
  9.     $showitems = ( $range * 2 )+1;
  10.    
  11.     $method = is_single() ? 'avia_post_pagination_link' : 'get_pagenum_link';
  12.     $method = apply_filters( 'avf_pagination_link_method', $method, $pages, $wrapper, $query_arg );
  13.  
  14.     if( 1 != $pages )
  15.     {
  16.         $output .= "<{$wrapper} class='pagination'>";
  17.         $output .= "<span class='pagination-meta'>" . sprintf( __( "Page %d of %d", 'avia_framework' ), $paged, $pages ) . "</span>";
  18.         $output .= ( $paged > 2 && $paged > $range + 1 && $showitems < $pages )? "<a href='" . avia_extended_pagination_link( $method, 1, $query_arg ) . "'>&laquo;</a>":'';
  19.         $output .= ( $paged > 1 && $showitems < $pages )? "<a href='" . avia_extended_pagination_link( $method, $prev, $query_arg ) . "'>&lsaquo;</a>":'';
  20.         $output .= ( $paged > 2 && $paged > $range + 1 && $showitems < $pages )? "<a href='" . avia_extended_pagination_link( $method, 1, $query_arg ) . "'>1</a>":'';
  21.         $output .= ( $paged > 2 && $paged - $range > 2 && $showitems < $pages )? "<span>&hellip;</span>":'';
  22.  
  23.         for( $i = 1; $i <= $pages; $i++ )
  24.         {
  25.             if( 1 != $pages &&( ! ( $i >= $paged+$range + 1 || $i <= $paged - $range-1 ) || $pages <= $showitems ) )
  26.             {
  27.                 switch( $i )
  28.                 {
  29.                     case ( $paged == $i ):
  30.                         $class = 'current';
  31.                         break;
  32.                     case ( ( $paged - 1 ) == $i ):
  33.                         $class = 'inactive previous_page';
  34.                         break;
  35.                     case ( ( $paged + 1 ) == $i ):
  36.                         $class = 'inactive next_page';
  37.                         break;
  38.                     default:
  39.                         $class = 'inactive';
  40.                         break;
  41.                 }
  42.                
  43.                 $output .= ( $paged == $i ) ? "<span class='{$class}'>{$i}</span>" : "<a href='" . avia_extended_pagination_link( $method, $i, $query_arg ) . "' class='{$class}' >{$i}</a>";
  44.             }
  45.         }
  46.  
  47.         $output .= ( $paged < $pages && $paged + $range < $pages - 1 && $showitems < $pages ) ? "<span>&hellip;</span>" :'';
  48.         $output .= ( $paged < $pages - 1 &&  $paged + $range - 1 < $pages && $showitems < $pages ) ? "<a href='" . avia_extended_pagination_link( $method, $pages, $query_arg ) . "'>" . $pages . "</a>":'';
  49.         $output .= ( $paged < $pages && $showitems < $pages ) ? "<a href='" . avia_extended_pagination_link( $method, $next, $query_arg ) . "'>&rsaquo;</a>" :'';
  50.         $output .= ( $paged < $pages - 1 &&  $paged + $range - 1 < $pages && $showitems < $pages ) ? "<a href='" . avia_extended_pagination_link( $method, $pages, $query_arg ) . "'>&raquo;</a>":'';
  51.         $output .= "</{$wrapper}>\n";
  52.     }
  53.  
  54.     return $output;
  55. }
  56.  
  57. add_filter('avf_pagination_output', 'enfold_pagination_output', 10, 5);
Add Comment
Please, Sign In to add comment