@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;
}