bbp_get_topic_pagination

Returns pagination links of a topic within the topic loop.

Description

(string) bbp_get_topic_pagination( (string) $args = '' ); 

Returns (string)

Pagination links

Parameters (1)

0. $args — Optional. (string) => ''
This function supports these arguments: - topic_id: Topic id - before: Before the links - after: After the links

Usage

  1. if ( !function_exists( 'bbp_get_topic_pagination' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/topics/template.php'; 
  3. $args = ''; 
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bbp_get_topic_pagination($args); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/topics/template.php  
  1. function bbp_get_topic_pagination( $args = '' ) { 
  2. global $wp_rewrite; 
  3.  
  4. // Bail if threading replies 
  5. if ( bbp_thread_replies() ) { 
  6. return; 
  7.  
  8. // Parse arguments against default values 
  9. $r = bbp_parse_args( $args, array( 
  10. 'topic_id' => bbp_get_topic_id(),  
  11. 'before' => '<span class="bbp-topic-pagination">',  
  12. 'after' => '</span>',  
  13. ), 'get_topic_pagination' ); 
  14.  
  15. // If pretty permalinks are enabled, make our pagination pretty 
  16. if ( $wp_rewrite->using_permalinks() ) { 
  17. $base = trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' ); 
  18. } else { 
  19. $base = add_query_arg( 'paged', '%#%', get_permalink( $r['topic_id'] ) ); 
  20.  
  21. // Get total and add 1 if topic is included in the reply loop 
  22. $total = bbp_get_topic_reply_count( $r['topic_id'], true ); 
  23.  
  24. // Bump if topic is in loop 
  25. if ( !bbp_show_lead_topic() ) 
  26. $total++; 
  27.  
  28. // Pagination settings 
  29. $pagination = array( 
  30. 'base' => $base,  
  31. 'format' => '',  
  32. 'total' => ceil( (int) $total / (int) bbp_get_replies_per_page() ),  
  33. 'current' => 0,  
  34. 'prev_next' => false,  
  35. 'mid_size' => 2,  
  36. 'end_size' => 3,  
  37. 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false 
  38. ); 
  39.  
  40. // Add pagination to query object 
  41. $pagination_links = paginate_links( $pagination ); 
  42. if ( !empty( $pagination_links ) ) { 
  43.  
  44. // Remove first page from pagination 
  45. if ( $wp_rewrite->using_permalinks() ) { 
  46. $pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $pagination_links ); 
  47. } else { 
  48. $pagination_links = str_replace( '&paged=1', '', $pagination_links ); 
  49.  
  50. // Add before and after to pagination links 
  51. $pagination_links = $r['before'] . $pagination_links . $r['after']; 
  52.  
  53. return apply_filters( 'bbp_get_topic_pagination', $pagination_links, $args );