Код: Выделить всё
function bbp_has_forums( $args = array() ) {
// Forum archive only shows root
if ( bbp_is_forum_archive() ) {
$default_post_parent = 0;
// User subscriptions shows any
} elseif ( bbp_is_subscriptions() ) {
$default_post_parent = 'any';
// Could be anything, so look for possible parent ID
} else {
$default_post_parent = bbp_get_forum_id();
}
$default_forum_search = bbp_sanitize_search_request( 'fs' );
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
// Default argument array
$default = array(
'post_type' => bbp_get_forum_post_type(),
'post_parent' => $default_post_parent,
'post_status' => bbp_get_public_status_id(),
'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
'orderby' => 'menu_order title',
'order' => 'ASC',
'no_found_rows' => true,
'ignore_sticky_posts' => true,
'posts_per_page' => 7,
'paged' => $paged, // page number is defined here.
// Conditionally prime the cache for last active posts
'update_post_family_cache' => true
);
// Only add 's' arg if searching for forums
// See https://bbpress.trac.wordpress.org/ticket/2607
if ( ! empty( $default_forum_search ) ) {
$default['s'] = $default_forum_search;
}
// Parse arguments with default forum query for most circumstances
$r = bbp_parse_args( $args, $default, 'has_forums' );
// Run the query
$bbp = bbpress();
$bbp->forum_query = new WP_Query( $r );
// Maybe prime last active posts
if ( ! empty( $r['update_post_family_cache'] ) ) {
bbp_update_post_family_caches( $bbp->forum_query->posts );
}
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $bbp->forum_query->max_num_pages
));
// Filter & return
return apply_filters( 'bbp_has_forums', $bbp->forum_query->have_posts(), $bbp->forum_query );
}
В архиве-форуме я сделал что-то подобное.
Код: Выделить всё
Подробнее здесь: https://stackoverflow.com/questions/663 ... inate-link