bbp_get_topic_pagination( mixed $args = '' )

Returns pagination links of a topic within the topic loop

Description

Parameters

$args

(mixed) (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

	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.