Wordpress 如何使用paginate_link()解决bbpress插件分页问题
因为我很难创建分页。我探索了在插件中直接添加\includes\forums\template.php的方法Wordpress 如何使用paginate_link()解决bbpress插件分页问题,wordpress,bbpress,Wordpress,Bbpress,因为我很难创建分页。我探索了在插件中直接添加\includes\forums\template.php的方法 function bbp_has_forums( $args = array() ) { // Forum archive only shows root if ( bbp_is_forum_archive() ) { $default_post_parent = 0; // User subscriptions shows any }
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 );
}
这不在子主题的function.php中,因为这是我唯一可以在任何地方使用paginate_links()的地方。或者我还缺什么
在归档论坛上,我做了这样的事情
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8" id="forum_index">
<?php
set_query_var('table_title', __translate( 'Discussion Groups', 'bbpress' ));
bbp_get_template_part( 'content', 'archive-forum' );
?>
<div class="forum_pagination font-weight-bold">
<?php echo paginate_links(); ?>
</div>
</div>
调用是一种重复,尽管它通过输出分页来工作,但默认情况下仅为1,2下一页或上一页1,2,如果我有更多的页面,则无法获得分页链接();在存档论坛中定义接受页码。您已经采取了正确的步骤;您需要在子模板中使用function.php来完成它,以强制每页发布文章 将其放在function.php中
function modify_forum_query($query) {
$query->set('posts_per_page', 7);
}
add_action('pre_get_posts', 'modify_forum_query');
你也可以在这里做任何你喜欢的事
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8" id="forum_index">
<?php
set_query_var('table_title', __translate( 'Discussion Groups', 'bbpress' ));
bbp_get_template_part( 'content', 'archive-forum' );
?>
<div class="forum_pagination font-weight-bold">
<?php echo paginate_links(); ?>
</div>
</div>
在您的echo paginate_links()中代码>,可以使用参数数组覆盖默认值