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
if ( !function_exists( 'bbp_get_topic_pagination' ) ) { require_once ABSPATH . PLUGINDIR . 'bbpress/includes/topics/template.php'; } $args = ''; // NOTICE! Understand what this does before running. $result = bbp_get_topic_pagination($args);
Defined (1)
The function is defined in the following location(s).
- /includes/topics/template.php
- function bbp_get_topic_pagination( $args = '' ) {
- global $wp_rewrite;
- // Bail if threading replies
- if ( bbp_thread_replies() ) {
- return;
- }
- // Parse arguments against default values
- $r = bbp_parse_args( $args, array(
- 'topic_id' => bbp_get_topic_id(),
- 'before' => '<span class="bbp-topic-pagination">',
- 'after' => '</span>',
- ), 'get_topic_pagination' );
- // If pretty permalinks are enabled, make our pagination pretty
- if ( $wp_rewrite->using_permalinks() ) {
- $base = trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' );
- } else {
- $base = add_query_arg( 'paged', '%#%', get_permalink( $r['topic_id'] ) );
- }
- // Get total and add 1 if topic is included in the reply loop
- $total = bbp_get_topic_reply_count( $r['topic_id'], true );
- // Bump if topic is in loop
- if ( !bbp_show_lead_topic() )
- $total++;
- // Pagination settings
- $pagination = array(
- 'base' => $base,
- 'format' => '',
- 'total' => ceil( (int) $total / (int) bbp_get_replies_per_page() ),
- 'current' => 0,
- 'prev_next' => false,
- 'mid_size' => 2,
- 'end_size' => 3,
- 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false
- );
- // Add pagination to query object
- $pagination_links = paginate_links( $pagination );
- if ( !empty( $pagination_links ) ) {
- // Remove first page from pagination
- if ( $wp_rewrite->using_permalinks() ) {
- $pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $pagination_links );
- } else {
- $pagination_links = str_replace( '&paged=1', '', $pagination_links );
- }
- // Add before and after to pagination links
- $pagination_links = $r['before'] . $pagination_links . $r['after'];
- }
- return apply_filters( 'bbp_get_topic_pagination', $pagination_links, $args );
- }