• Resolved ravi642

    (@ravi642)


    Is there any way, i can display badge title or badge image or user ranks of each user in leaderboard?

    The short-code ‘[mycred_leaderboard]’ only provied Positions, names and points to display on the leaderboard.

Viewing 4 replies - 1 through 4 (of 4 total)
  • A.Tariq

    (@arsalantariq)

    Hi @ravi642,

    Thank you for contacting us, You can use the below-shared hook to achieve what you are looking for.

    https://codex.mycred.me/filters/mycred_ranking_row/

    Thread Starter ravi642

    (@ravi642)

    Hi @arsalantariq

    Thank you for replying. But above filter is for adding Avatar of users not for Badge title. and I want to add column for Badge Title of each user.

    Thread Starter ravi642

    (@ravi642)

    @arsalantariq

    is there any way, I can do this?

    A.Tariq

    (@arsalantariq)

    @ravi642,

    Add the below code snippet in your themes functions.php file to display user’s earned badges in leaderboard.
    add_filter('mycred_ranking_row','badge_ranking_rows', 10, 5 ); function badge_ranking_rows( $layout, $template, $row, $position, $badge ) {
    $user_id = $row['ID']; $all_badges = mycred_get_badge_ids(); $profile_user_id = mycred_get_user_id( $user_id ); $users_badges = mycred_get_users_badges( $profile_user_id, true ); $user_id = mycred_get_user_id( $user_id ); $badges = ''; ob_start(); echo '<div class="row" id="mycred-users-badges"><div class="col-xs-12">'; foreach ( $all_badges as $badge_id ) { echo '<div class="the-badge">'; $page_id = get_page($badge_id); $badge_id = absint( $badge_id ); $has_earned = mycred_get_badge( $badge_id ); $badge = mycred_get_badge( $badge_id ); $users_badges = mycred_get_users_badges($profile_user_id ); $mycred = mycred(); if ( array_key_exists( $badge_id, $users_badges ) ) { $earned = 1; $earned_level = $users_badges[ $badge_id ]; $badge_image = $badge->get_image( $earned_level ); } if( $has_earned ) { $badge_title = $has_earned->title; $badge_img = $has_earned->main_image; $level_image = $has_earned->level_image; $show_img = $has_earned->user_has_badge( $profile_user_id ); if( $show_img ) { $earned_badge_image = ! empty( $has_earned->level_image ) ? $has_earned->level_image : $has_earned->main_image; $layout .= '<div class="demo-badge-image">' . wp_kses_post( $earned_badge_image ) . '</div>'; $layout .= '<div class="demo-badge-title">' . esc_html( $badge_title ) . ' '.'</div>'; $layout .= '<div class="page-excerpt">' . wp_kses_post( $page_id->post_excerpt ) . ' '.'</div>'; // $badges .= $layout; } } } return $layout;
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add extra columns to leaderboard short-code to show badge title of each user’ is closed to new replies.