Advertisement
miriamdepaula

WordPress: Paginando 2a. query dentro de tpl page/single

Nov 15th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2. /*
  3. paginação de segunda query, dentro de qualquer template page.
  4. */
  5.  
  6. if (isset($_GET['pg'])) $cur_page = absint($_GET['pg']);
  7. else $cur_page = 1;
  8.                    
  9. $args = array( 'post_type' => 'product', 'posts_per_page' => 5, 'paged' => $cur_page );            
  10.                
  11. $wp_query = new WP_Query($args);               
  12.                
  13. while ( $wp_query->have_posts() ) : $wp_query->the_post();
  14.            
  15.     echo '<h2>' . get_the_title() . '</h2>';
  16.  
  17.     echo get_the_content(); //ou get_the_excerpt()
  18.  
  19. endwhile;
  20.                
  21.  
  22. $page_links_total =  $wp_query->max_num_pages;
  23. $page_links = paginate_links( array(
  24.           'base' => add_query_arg( 'pg', '%#%' ),  //pg é a variavel que vai aparecer na url ?pg=1 ....
  25.           'format' => '',
  26.           'prev_text' => __('&laquo;'),
  27.           'next_text' => __('&raquo;'),
  28.           'total' => $page_links_total,
  29.           'current' => $cur_page
  30.         ));
  31.                
  32. if ( $page_links ) echo '<div class="paging">'. $page_links .'</div>';
  33.                
  34. wp_reset_query();
  35.  
  36. ?>
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement