Marcos_Alexandre

Untitled

Nov 8th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. No arquivo Functions:
  2.  
  3. function wp_pagination( $query=null, $wpcpn_posts=null )
  4. {
  5.     global $wp_query;
  6.     $query = $query ? $query : $wp_query;
  7.     $big = 999999999;
  8.     $max_num_pages = $query->max_num_pages;
  9.  
  10.     $paginate = paginate_links(
  11.         array(
  12.             'base'      => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
  13.             'type'      => 'array',
  14.             'total'     => $max_num_pages,
  15.             'format'    => '?paged=%#%',
  16.             'current'   => max( 1, get_query_var('page') ),
  17.             'prev_text' => __('«'),
  18.             'next_text' => __('»'),
  19.         )
  20.     );
  21.     if ( $max_num_pages > 1 && $paginate ) {
  22.         echo '<div class="pagination">';
  23.         foreach ( $paginate as $page ) {
  24.             echo '<spam>' . $page . '</spam>';
  25.         }
  26.         echo '</div>';
  27.     }
  28. }
  29.  
  30.  
  31. No arquivo da página:
  32.  
  33.             <?php
  34.  
  35.                 $page = (get_query_var('page')) ? get_query_var('page') : 1;
  36.  
  37.                 $args = array (
  38.                     'posts_per_page' => 10,
  39.                     'paged' => $page
  40.                 );
  41.                 $my_query = new WP_Query ($args);
  42.                 $GLOBALS['wp_query']->max_num_pages = $my_query->max_num_pages;
  43.                
  44.            
  45.                 while ( $my_query->have_posts() ) : $my_query->the_post();
  46.            
  47.                 endwhile;
  48.            
  49.                 if ( function_exists( 'wp_pagination' ) )
  50.                   wp_pagination($my_query);
  51.             ?>
Advertisement
Add Comment
Please, Sign In to add comment