douyuefei3546 2016-12-12 10:11
浏览 88
已采纳

如何在Buddypress上显示添加页面的分页

I'm using Buddypress 2.7.2 on Wordpress 4.6.1. I added a new page using the function by bp_core_new_nav_item() on BuddyPress for expanding pages.
On that page, there are ten Post-type artcles each page , the pagination are displayed under the page. However, if I click on page 2 or later of the page, I can not find the link destination. I wrote on the added page as follows.

<?php
$paged = get_query_var('paged');
$args = array(
    'posts_per_page' => 10,
    'paged' => $paged,
    'orderby' => 'post_date',
    'order' => 'DESC',
    'post_type' => 'post',
    'post_status' => 'publish'
);
$the_query = new WP_Query($args);

if ( $the_query->have_posts() ) :
    while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php
$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' => $the_query->max_num_pages
) );
?>

<?php else: ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>

For example, the pagination link is as follows.
Page 1
Top page is not the problem.
[this is not a link](http://example.com/member/username/custom/
After 2 pages
The link destination does not exist.
[this is not a link](http://example.com/member/username/custom/page/2/ page/3/ page/4/ ........

I don't know why I can not find the 2 page or later. If you know the solution, please let me know.

  • 写回答

1条回答 默认 最新

  • du4629 2016-12-12 18:37
    关注

    This is one way to handle pagination in your situation. It is probably not the best or the 'correct' way...

    Add the $paged value to the url.

    For example:

    $paged = ( isset( $_GET['xj'] ) ) ? $_GET['xj'] : 1;
    $args = array( ... etc. 
    

    And then adjust your pagination to use that variable:

    echo paginate_links( array(
            'base' => esc_url( add_query_arg( 'xj', '%#%' ) ),
            'format' => '',
            'total' => ceil( (int) $wp_query->found_posts / (int) get_query_var('posts_per_page') ),
            'current' => (int) get_query_var('paged'),
        ) );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料