簡體   English   中英

如何在Buddypress上顯示添加頁面的分頁

[英]How to display the pagination of the added page on Buddypress

我在Wordpress 4.6.1上使用了Buddypress 2.7.2。 我在BuddyPress上使用bp_core_new_nav_item()函數添加了一個新頁面來擴展頁面。
在該頁面上,每頁有十個Post-type artcles,分頁顯示在頁面下方。 但是,如果我單擊頁面的第2頁或更高版本,我找不到鏈接目標。 我在添加的頁面上寫了如下。

<?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; ?>

例如,分頁鏈接如下。
第1頁
首頁不是問題。
[這不是鏈接]( http://example.com/member/username/custom/
2頁后
鏈接目標不存在。
[這不是鏈接]( http://example.com/member/username/custom/page/2/ page / 3 / page / 4 / ........

我不知道為什么我找不到2頁或更晚。 如果您知道解決方案,請告訴我。

這是在您的情況下處理分頁的一種方法。 它可能不是最好的或“正確的”方式......

$paged值添加到url。

例如:

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

然后調整您的分頁以使用該變量:

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'),
    ) );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM