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'),
        ) );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法