0

我正在使用 buddypress 主题 [buddyboss] ( http://buddyboss.com/ )。主要原因是这个主题能够管理图片库(效果很好)。

我现在想在成员循环中调用该图片功能。其中一位 buddyboss-admins 告诉我:

“您将需要 buddy_boss_pics.php 中的函数。具体而言,您需要使用函数 buddyboss_pics_screen_picture_grid_content() 从第 285 行开始。您需要编辑文件以使用成员循环,因为它当前使用 display_user_id。”

这是函数的外观:

function buddyboss_pics_screen_picture_grid_content()
{
    global $bp, $wpdb, $bbpics;

    $wpdb->show_errors = BUDDY_BOSS_DEBUG;

    $img_size = is_active_sidebar( 'Profile' ) ? 'buddyboss_pic_med' : 'buddyboss_pic_wide';

    $gallery_class = is_active_sidebar( 'Profile' ) ? 'gallery has-sidebar' : 'gallery';

    $user_id = $bp->displayed_user->id;
    $activity_table = $wpdb->prefix."bp_activity";
    $activity_meta_table = $wpdb->prefix."bp_activity_meta";

    $pages_sql = "SELECT COUNT(*) FROM $activity_table a INNER JOIN $activity_meta_table am ON a.id = am.activity_id WHERE a.user_id = $user_id AND meta_key = 'bboss_pics_aid'";

    $bbpics->grid_num_pics = $wpdb->get_var($pages_sql);

    $bbpics->grid_current_page = isset( $_GET['page'] ) ? (int) $_GET['page'] : 1;

    // Prepare a SQL query to retrieve the activity posts 
    // that have pictures associated with them
    $sql = "SELECT a.*, am.meta_value FROM $activity_table a INNER JOIN $activity_meta_table am ON a.id = am.activity_id WHERE a.user_id = $user_id AND meta_key = 'bboss_pics_aid' ORDER BY a.date_recorded DESC";

    buddy_boss_log("SQL: $sql");

    $pics  = $wpdb->get_results($sql,ARRAY_A);

    $bbpics->grid_pagination = new BuddyBoss_Paginated( $pics, $bbpics->grid_pics_per_page, $bbpics->grid_current_page );

    buddy_boss_log("RESULT: $pics");

    // If we have results let's print out a simple grid
    if ( !empty( $pics ) )
    {
        $bbpics->grid_had_pics = true;
        $bbpics->grid_num_pics = count( $pics );

任何帮助都会很棒,因为我真的需要这样做!

4

2 回答 2

0

未经测试 - 但试试这个:

在成员循环中,寻找

                <?php
             /***
              * If you want to show specific profile fields here you can,
              * but it'll add an extra query for each member in the loop
              * (only one regadless of the number of fields you show):
              *
              * bp_member_profile_data( 'field=the field name' );
              */
            ?>

在关闭 php 标记之前添加这个?>

             buddyboss_pics_members_loop( bp_get_member_user_id() );

将 buddyboss_pics_screen_picture_grid_content() 函数复制到成员循环的底部。

将其放在php标签之间并将名称更改为 buddyboss_pics_members_loop( $user_id )

并注释掉或删除 $user_id = $bp->displayed_user->id;

于 2012-04-17T19:05:31.980 回答
0

这里的 buddyboss_pics_screen_picture_grid_content() 函数主要是使用 user_id 并从数据库中获取图像。

很简单,您已经在 member-loop.php 文件的 while 循环中调用了该函数: buddyboss_pics_screen_picture_grid_content(bp_member_user_id())

这里传递这个函数的参数member_user_id。

小编辑buddyboss_pics_screen_picture_grid_content()下面的主要功能:

以下变化:

function buddyboss_pics_screen_picture_grid_content($user_id = null)
{

    //Remove this code
    $user_id = $bp->displayed_user->id;

    //Put new Code
    if (empty($user_id)) {
        $user_id = $bp->displayed_user->id;
    } else {
        $user_id = $user_id;
    }

}  
于 2012-11-29T06:00:30.873 回答