Course leaderboard

Home Forums Legacy Support Support queries How-to & Troubleshooting Course leaderboard

Tagged: 

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #202640
    hilmanf
    Spectator
    Hi, I need to motivate my studing by showing them course leaderboard. Not quiz leaderboard. It will shows: Rank #; Name of student; course mark Rank needs to show big 10 and this leaderboard sync automatically to course statistic. Need help to achieve this. Thanks.
    #202748
    logan
    Member
    Hello, Please add this code in your wplms-customizer.php file in wplms customizer plugin : add_shortcode('course_leaderboard',function ($atts,$content=null){ global $wpdb; $students  =  $wpdb->get_results($wpdb->prepare(" SELECT pm.meta_key,pm.meta_value FROM {$wpdb->postmeta} AS pm LEFT JOIN {$wpdb->posts} as p ON pm.post_id = p.ID WHERE p.post_status = %s AND p.post_type = %s AND p.ID = %d AND pm.meta_key REGEXP '^[0-9]+$' ORDER BY pm.meta_value DESC ",'publish','course',$atts['course']));   if(!empty($students)){ echo '<ol class="students">'; foreach ($students as $key => $stu) { $student = get_user_by('id',$stu->meta_key); if(!empty($student) && !is_wp_error($student)){   echo '<li><span style="width: 50% !important;display: inline-block; font-size: 18px;">'.bp_core_get_user_displayname($student->ID).'</span><span style="width: 50% !important;display: inline-block; font-size: 18px;">'.$stu->meta_value.'</span></li>'; } } echo '</ul>'; } }); then create a new page with short code: refer=> http://prntscr.com/n5vz84 Effects will be made as: http://prntscr.com/n5vzku
    #203198
    hilmanf
    Spectator
    Hi Logan, Your code is awesome. But the list shows all student rank. http://prntscr.com/n7bbb1 I only need 10 big on the list. Would you please create the shortcode that I can arrange the list like .. [course_leaderboard course="2065" count="10"] Where count is the number of student shows on the list. Thanks buddy.
    #203283
    logan
    Member
    Hello, replace by this code: add_shortcode('course_leaderboard',function ($atts,$content=null){   global $wpdb; if(!isset($atts['count'])){ $atts['count'] =10; } $students  =  $wpdb->get_results($wpdb->prepare(" SELECT pm.meta_key,pm.meta_value FROM {$wpdb->postmeta} AS pm LEFT JOIN {$wpdb->posts} as p ON pm.post_id = p.ID WHERE p.post_status = %s AND p.post_type = %s AND p.ID = %d AND pm.meta_key REGEXP '^[0-9]+$' ORDER BY pm.meta_value DESC LIMIT 0,{$atts['count']} ",'publish','course',$atts['course'])); if(!empty($students)){     echo '<ul class="student_list_title"> <li> <span style="display: inline-block;background: #313b3d40;width: 50% !important;"> Student Name </span> <span style="display: inline-block;background: #313b3d40;width: 49% !important;"> Marks </span> </li> </ul>';   echo '<ol class="students">'; foreach ($students as $key => $stu) { $student = get_user_by('id',$stu->meta_key); if(!empty($student) && !is_wp_error($student)){ echo '<li><span style="width: 50% !important;display: inline-block; font-size: 18px;">'.bp_core_get_user_displayname($student->ID).'</span><span style="width: 50% !important;display: inline-block; font-size: 18px;">'.$stu->meta_value.'</span></li>';   } } echo '</ul>'; } }); use this shortcode: [course_leaderboard course="2065" count="10"] Refer: http://prntscr.com/n7fz5r
    #203376
    hilmanf
    Spectator
    Thanks Logan. But I can't put any text above the shortcode. Need help to fix this. Front end: http://prntscr.com/n7uo0f Back end: http://prntscr.com/n7unrt
    #203406
    logan
    Member
    Hello, I have updated the code. replace above with this one: add_shortcode('course_leaderboard',function ($atts,$content=null){ ob_start();   global $wpdb; if(!isset($atts['count'])){ $atts['count'] =10; } $students  =  $wpdb->get_results($wpdb->prepare(" SELECT pm.meta_key,pm.meta_value FROM {$wpdb->postmeta} AS pm LEFT JOIN {$wpdb->posts} as p ON pm.post_id = p.ID WHERE p.post_status = %s AND p.post_type = %s AND p.ID = %d AND pm.meta_key REGEXP '^[0-9]+$' ORDER BY pm.meta_value DESC LIMIT 0,{$atts['count']} ",'publish','course',$atts['course'])); if(!empty($students)){     echo '<ul class="student_list_title"> <li> <span style="display: inline-block;background: #313b3d40;width: 50% !important;"> Student Name </span> <span style="display: inline-block;background: #313b3d40;width: 49% !important;"> Marks </span> </li> </ul>';   echo '<ol class="students">'; foreach ($students as $key => $stu) { $student = get_user_by('id',$stu->meta_key); if(!empty($student) && !is_wp_error($student)){ echo '<li><span style="width: 50% !important;display: inline-block; font-size: 18px;">'.bp_core_get_user_displayname($student->ID).'</span><span style="width: 50% !important;display: inline-block; font-size: 18px;">'.$stu->meta_value.'</span></li>';   } } echo '</ul>'; } $html = ob_get_clean(); return $html; }); Refer: http://prntscr.com/n7wc4s
    Tip: You could create course specific leaderboards.

    Refer this tutorial: https://wplms.io/support/knowledge-base/wplms-course-custom-nav-plugin/

    Follow this:

    1. http://prntscr.com/n7axph then re-save permalinks.
    2. Goto wp-admin > lms > settings > general setting > course menu > reset this setting.Refer: http://prntscr.com/n7ayom
    3. goto course frontend editor and under settings tab find the added menu. here you can add your description. refer: http://prntscr.com/n7wdvl
    4. http://prntscr.com/n7b6wj
    #203494
    hilmanf
    Spectator
    Thank you, buddy.
    #203551
    logan
    Member
    Dear Friend, Glad you’re enjoying the theme & support – thanks for using it! :) Please write your review. I would really appreciate that! Here: https://themeforest.net/item/wplms-learning-management-system/reviews/6780226 If I can be of assistance, please do not hesitate to contact me again. Closing this topic.
Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Course leaderboard’ is closed to new replies.