Advertisement
larinmj

paginação

Nov 21st, 2019
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.95 KB | None | 0 0
  1.  if ( have_posts() ) :
  2. $the_query = new WP_Query(array(
  3.         'post_type'         => 'marketplace',
  4.         'posts_per_page'    => -1,
  5.         'meta_key'          => 'prioridade',
  6.         'orderby'           => 'meta_value',
  7.         'order'             => 'ASC'
  8.         ));
  9.                            
  10. while( $the_query->have_posts() ) : $the_query->the_post();
  11.  
  12.  
  13.  
  14. function pagination_numeric_posts_nav_marketplace() {
  15.  
  16.     if( is_singular() )
  17.         return;
  18.  
  19.         $args = array(    
  20.         'post_type' => 'marketplace',
  21.         );
  22.         $the_query = new WP_Query( $args );
  23.  
  24.     if(  $the_query->max_num_pages <= 1 )
  25.         return;
  26.  
  27.     $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
  28.     $max   = intval(  $the_query->max_num_pages );
  29.  
  30.     if ( $paged >= 1 )
  31.         $links[] = $paged;
  32.  
  33.     if ( $paged >= 3 ) {
  34.         $links[] = $paged - 1;
  35.         $links[] = $paged - 2;
  36.     }
  37.  
  38.     if ( ( $paged + 2 ) <= $max ) {
  39.         $links[] = $paged + 2;
  40.         $links[] = $paged + 1;
  41.     }
  42.  
  43.     echo '<div class="paged-nav navigation"><ul>' . "\n";
  44.  
  45.     if ( ! in_array( 1, $links ) ) {
  46.         $class = 1 == $paged ? ' class="active"' : '';
  47.  
  48.         printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
  49.  
  50.         if ( ! in_array( 2, $links ) )
  51.             echo '<li><span class="intervalo">…</span></li>';
  52.     }
  53.  
  54.     sort( $links );
  55.     foreach ( (array) $links as $link ) {
  56.         $class = $paged == $link ? ' class="active"' : '';
  57.         printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
  58.     }
  59.  
  60.     if ( ! in_array( $max, $links ) ) {
  61.         if ( ! in_array( $max - 1, $links ) )
  62.             echo '<li><span class="intervalo">…</span></li>' . "\n";
  63.  
  64.         $class = $paged == $max ? ' class="active"' : '';
  65.         printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
  66.     }
  67.     echo '</ul></div>' . "\n";
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement