bbp_get_topic_pagination( mixed $args = '' )

Returns pagination links of a topic within the topic loop

Description

Parameters

$args

(Optional) This function supports these arguments: - topic_id: Topic id - before: Before the links - after: After the links

Default value: ''

Return

(string) Pagination links

Source

File: bp-forums/topics/template.php

872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
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( '&#038;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 );
}

Changelog

Changelog
Version Description
bbPress (r2966) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.