Buddypress中的自定义分页

时间:2018-05-15 20:54:01

标签: php wordpress buddypress

我有一个自定义的buddypress好友列表页面,显示好友视频,并且我已将per_page设置为50.如果用户有超过50个朋友,我如何对好友列表进行分页?

<div class="dashboard-wrapper">
<h1>My Friends' Videos</h1>
<a href="?part=default" class="button">Dashboard</a><br>
<?php
$user_id = bp_is_user() ? bp_displayed_user_id() : bp_loggedin_user_id();

$args = apply_filters('bp_show_friends_args', array(
    'user_id' => $user_id,
    'type' => 'active',
    'per_page' => 50,
    'max' => $limit,
    'populate_extra' => 0
        )
);

if (bp_has_members($args)) {
    ?>
    <ul class="bpsf-members">
        <?php while (bp_members()) : bp_the_member(); ?>

            <li class="bpsf-member">
                <?php bp_member_name(); ?>
                <div class="item-avatar">
                    <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name(); ?>">
                        <?php bp_member_avatar($avatar_args) ?><?php display_friend_colors(bp_get_member_user_id()); ?>
                    </a>

                </div>
                <?php do_action('bp_show_friends_after_friend_avatar', bp_get_member_user_id()); ?><div class="cleared"></div>
                <div class="videos">
                    <ul>
                        <?php
                        $args = array(
                            'author' => bp_get_member_user_id(),
                            'orderby' => 'post_date',
                            'order' => 'DESC',
                            'post_type' => 'member_video',
                            'posts_per_page' => -1 // no limit
                        );
                        $current_user_posts = get_posts($args);
                        foreach ($current_user_posts as $post) : setup_postdata($post);
                            $thumbnail = get_post_meta(get_the_ID(), 'thumbnail');
                            //d($thumbnail);
                            ?>
                            <li>
                                <a href="<?php the_permalink(); ?>"><img src="<?= $thumbnail[0] ?>" /></a>
                                <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
                            </li>
                            <?php
                        endforeach;
                        wp_reset_postdata();
                        ?>
                    </ul>
                </div>
                <div class="cleared"></div>
            </li>

        <?php endwhile; ?>
    </ul>
<?php }
?>

我已经在线查看了buddypress示例代码,但我无法找到任何提示

1 个答案:

答案 0 :(得分:0)

$user_id = bp_is_user() ? bp_displayed_user_id() : bp_loggedin_user_id();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = apply_filters('bp_show_friends_args', array(
    'user_id' => $user_id,
    'type' => 'active',
    'per_page' => 20,
    'paged' => $paged,
    // 'max' => $limit,
    'populate_extra' => 0
        )
);

if (bp_has_members($args)) {
    ?>
    <div id="pagination">
        <ul class="pagination">
            <li id="previous-stories" class="arrow">
                <?php bp_members_pagination_links(); ?>
            </li>
         </ul>
    </div><!-- /#pagination -->
.......