WordPress.org

Ready to get started?Download WordPress

Forums

Achievements for WordPress
[resolved] How-To: Create a Leaderboard (77 posts)

  1. mikebronner
    Member
    Posted 1 year ago #

    Creating a leader-board is actually fairly easy. Granted, it's no short code, but using a custom post template, you can do it. I have created a leaderboard using the following code:

    <?php
    /*
    Template Name: Roster
    */
    	get_header();
    ?>
    
    <table id="roster">
    	<tr>
    		<th>Avatar</th>
    		<th>Name</th>
    		<th>Rank</th>
    <?php
    	if (is_user_logged_in())
    	{
    ?>
    		<th>Advancement</th>
    		<th>Email</th>
    <?php
    	}
    ?>
    		<th>Member Since</th>
    	</tr>
    <?php
    	$listUsersID = $wpdb->get_col(
    		$wpdb->prepare(
    			"SELECT $wpdb->users.ID FROM $wpdb->users ORDER BY %s ASC",
    			"konb_user_level, nickname"
    		)
    	);
    foreach ( $listUsersID as $userid )
    {
    	$user = get_userdata( $userid );
    ?>
    	<tr>
    		<td><?php echo get_avatar($userid, $size = '33'); ?></td>
    		<td><? echo $user->nickname; ?></td>
    		<td><?
    if ( !empty( $user->roles ) && is_array( $user->roles ) )
    {
    	foreach ( $user->roles as $role )
    	{
    		if (strpos($role, "bbp_") === false)
    		{
    			echo ucfirst(strtolower($role));
    		}
    	}
    }
    		?></td>
    		<td><?php echo dpa_get_user_points( $user->ID ); ?></td>
    <?php
    	if (is_user_logged_in())
    	{
    ?>
    		<td><? echo $user->user_email; ?></td>
    <?php
    	}
    ?>
    		<td><? echo $user->user_registered; ?></td>
    	</tr>
    <?php
    }
    ?>
    </table>
    <?php
    	comments_template( '', true );
    	get_sidebar();
    	get_footer();

    This code is saved in the root of my child theme as roster.php. You will be able to use it by creating a normal page in WordPress, then selecting the Roster template. Feel free to modify and customize as needed. I'd show a working example, except our roster page requires the user to be logged in.

    Using a custom page template you can fully customize the roster to your liking, where as with a short code, you'd be very dependent on how the layout was done in the plugin.

    ~Mike

    http://wordpress.org/extend/plugins/achievements/

  2. Paul Gibbs
    BuddyPress Lead Developer
    Plugin Author

    Posted 1 year ago #

    One of the problems with this is that you've used a direct SQL query (without caching; without a LIMIT) that won't scale. Let's pretend I run the above on a site with 25,000 user accounts. On most hosts, this will just crash the page :)

    This scalability and problems over getting data out the usermeta table (where the points are scored) is why a scoreboard didn't make it into a recent release yet :)

    You've also got some checks in it for bbPress roles and ordering by a column "konb_user_level" (I hope your wp_user table doesn't have non-standard columns!).

  3. mikebronner
    Member
    Posted 1 year ago #

    Hi Paul,

    You're right, there's no pagination or anything of the sort to prevent huge queries.

    My database prefix is konb_ instead of wp_, all tables are standard out of the box and plugins. Yes, I do have some bbPress fields in it, but this is only an example. Should easily adapt to vanilla WP.

  4. pmcvicker
    Member
    Posted 1 year ago #

    This might work for what I need in the short term. I only need the username, avatar, and points columns, but I wonder, as you have it set up it sorts by when the user registered. How would I have the table sort by points instead, descending in value, in the traditional leaderboard fashion?

  5. mikebronner
    Member
    Posted 1 year ago #

    Paul is right in that this query is less than optimal. The query would have to be updated to include taxonomies.

    Let me see if I can improve this to WP_QUERY instead, and use the functionality that WordPress provides.

  6. pmcvicker
    Member
    Posted 1 year ago #

    Thanks Mike! A leaderboard is one of the last pieces I need for a project I'm launching at the end of the month. Anything you could offer would be greatly appreciated!

  7. Paul Gibbs
    BuddyPress Lead Developer
    Plugin Author

    Posted 1 year ago #

    FOR EVERYONE READING: This particular technique has not been tested by me, and so it's not recommend. If you break your code or your server, it's your problem. :)

  8. mikebronner
    Member
    Posted 1 year ago #

    ^^^^^ What Paul says! ^^^^^^ Use at own risk. I use the leaderboard on a members-only page and we have under 100 members, so I'm comfortable with the current risks. I will see if I can get a working query in place that has some limitations and pagination to prevent the system bogging down.

  9. mikebronner
    Member
    Posted 1 year ago #

    Here is the code for a bit more solid query that should work on all WP sites that have Achievements installed. This query now features pagination and orders by total Karma points in descending order.

    <?php
    /*
    Template Name: Roster
    */
    	get_header();
    
    	global $wpdb, $current_date;
    
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $post_per_page = intval(get_query_var('posts_per_page'));
        $offset = ($paged - 1)*$post_per_page;
    	$listUsersID = $wpdb->get_col
    	(
    		$wpdb->prepare
    		(
    			'SELECT SQL_CALC_FOUND_ROWS person.*
    				,nick.meta_value
    				,SUM(karma.meta_value)
    			FROM konb_users AS person
    			LEFT JOIN konb_usermeta as nick
    				ON person.id = nick.user_id
    				AND nick.meta_key = "nickname"
    			LEFT JOIN konb_usermeta as karma
    				ON person.id = karma.user_id
    				AND karma.meta_key = "konb__dpa_points"
    			GROUP BY nick.meta_value
    				,person.ID
    			ORDER BY karma.meta_key DESC
    			LIMIT ' . $offset . ', ' . $post_per_page . ';'
    		)
    	);
    	$sql_posts_total = $wpdb->get_var( "SELECT FOUND_ROWS();" );
        $max_num_pages = ceil($sql_posts_total / $post_per_page);
    ?>
    
    <table id="roster">
    	<tr>
    		<th>Avatar</th>
    		<th>Name</th>
    		<th>Rank</th>
    <?php
    	if (is_user_logged_in())
    	{
    ?>
    		<th>Advancement</th>
    		<th>Email</th>
    <?php
    	}
    ?>
    		<th>Member Since</th>
    	</tr>
    <?php
    foreach ( $listUsersID as $userid )
    {
    	$user = get_userdata( $userid );
    ?>
    	<tr>
    		<td><?php echo get_avatar($userid, $size = '33'); ?></td>
    		<td><? echo $user->nickname; ?></td>
    		<td><?
    if ( !empty( $user->roles ) && is_array( $user->roles ) )
    {
    	foreach ( $user->roles as $role )
    	{
    		if (strpos($role, "bbp_") === false)
    		{
    			echo ucfirst(strtolower($role));
    		}
    	}
    }
    		?></td>
    		<td><?php echo dpa_get_user_points( $user->ID ); ?></td>
    <?php
    	if (is_user_logged_in())
    	{
    ?>
    		<td><? echo $user->user_email; ?></td>
    <?php
    	}
    ?>
    		<td><? echo $user->user_registered; ?></td>
    	</tr>
    <?php
    }
    ?>
    </table>
    <div class="navigation">
        <div class="previous panel"><?php previous_posts_link('« Previous Page',$max_num_pages) ?></div>
        <div class="next panel"><?php next_posts_link('Next Page »',$max_num_pages) ?></div>
    </div>
    <?php
    	comments_template( '', true );
    	get_sidebar();
    	get_footer();

    The only reason I haven't used WP_USER_QUERY to do this, is because I can't for the life of me figure out how to do aggregate functions in WP_USER_QUERY. If someone knows the answer, please share. :)

  10. pmcvicker
    Member
    Posted 1 year ago #

    Pagination works great but for some reason its not sorting by karma value. Looking closer at the sort order, I can't really tell by what value it is sorting, as there doesn't appear to be any pattern.

    Also, how much trouble would it be to add a numerical rank as a column for each user, so a person could see, "hey, I'm number 43 on the leaderboard right now"?

  11. mikebronner
    Member
    Posted 1 year ago #

    Doh! When I tested I guess it was coincidence that it worked for me. :) I also added the rank as the first column. I don't have this in the query, as it is something very easily calculated on the front-end:

    <?php
    /*
    Template Name: Roster
    */
    	get_header();
    
    	global $wpdb, $current_date;
    
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $post_per_page = intval(get_query_var('posts_per_page'));
        $offset = ($paged - 1)*$post_per_page;
    	$listUsersID = $wpdb->get_col
    	(
    		$wpdb->prepare
    		(
    			'SELECT SQL_CALC_FOUND_ROWS person.*
    				,nick.meta_value
    				,SUM(karma.meta_value) AS total_karma
    			FROM konb_users AS person
    			LEFT JOIN konb_usermeta as nick
    				ON person.id = nick.user_id
    				AND nick.meta_key = "nickname"
    			LEFT JOIN konb_usermeta as karma
    				ON person.id = karma.user_id
    				AND karma.meta_key = "konb__dpa_points"
    			GROUP BY nick.meta_value
    				,person.ID
    			ORDER BY total_karma DESC
    			LIMIT ' . $offset . ', ' . $post_per_page . ';'
    		)
    	);
    	$sql_posts_total = $wpdb->get_var( "SELECT FOUND_ROWS();" );
        $max_num_pages = ceil($sql_posts_total / $post_per_page);
    ?>
    
    <table id="roster">
    	<tr>
    		<th>Rank</th>
    		<th>Avatar</th>
    		<th>Name</th>
    		<th>Rank</th>
    <?php
    	if (is_user_logged_in())
    	{
    ?>
    		<th>Advancement</th>
    		<th>Email</th>
    <?php
    	}
    ?>
    		<th>Member Since</th>
    	</tr>
    <?php
    $counter = 1;
    foreach ( $listUsersID as $userid )
    {
    	$user = get_userdata( $userid );
    ?>
    	<tr>
    		<td><?php echo $counter++; ?></td>
    		<td><?php echo get_avatar($userid, $size = '33'); ?></td>
    		<td><? echo $user->nickname; ?></td>
    		<td><?
    if ( !empty( $user->roles ) && is_array( $user->roles ) )
    {
    	foreach ( $user->roles as $role )
    	{
    		if (strpos($role, "bbp_") === false)
    		{
    			echo ucfirst(strtolower($role));
    		}
    	}
    }
    		?></td>
    		<td><?php echo dpa_get_user_points( $user->ID ); ?></td>
    <?php
    	if (is_user_logged_in())
    	{
    ?>
    		<td><? echo $user->user_email; ?></td>
    <?php
    	}
    ?>
    		<td><? echo $user->user_registered; ?></td>
    	</tr>
    <?php
    }
    ?>
    </table>
    <div class="navigation">
        <div class="previous panel"><?php previous_posts_link('&laquo; Previous Page',$max_num_pages) ?></div>
        <div class="next panel"><?php next_posts_link('Next Page &raquo;',$max_num_pages) ?></div>
    </div>
    <?php
    	comments_template( '', true );
    	get_sidebar();
    	get_footer();
  12. pmcvicker
    Member
    Posted 1 year ago #

    Ah! Beautiful. Everything appears to be sorting properly. I did notice that the rank column resets at each new page advance, as its numbering only that list of users for the given page.

    Excellent work Mike!

  13. mikebronner
    Member
    Posted 1 year ago #

    Ah, no problem. Replace $counter = 1; with $counter = $offset + 1;

    Glad its working for you. Please do keep in mind though that this is unsupported functionality and may not scale well in some cases. :)

  14. mikebronner
    Member
    Posted 1 year ago #

    Just saw the leaderboard you implemented!!!! Hats off to you sir! Love it :)

    http://challengebeta.mypcls.org/leaderboard/

  15. pmcvicker
    Member
    Posted 1 year ago #

    Thanks!

    Got me to thinking, I wonder if there's a good way to pull the position number for the current logged in user separately outside of the table. I'd like to put it above the table to save users the trouble from scrolling through a long table to find their name, since I expect we'll have over a thousand participants this summer.

  16. mikebronner
    Member
    Posted 1 year ago #

    Ah! Yes, that's completely doable. I'll add that to the list to do. Good idea, something I'll want as well down the road.

  17. mikebronner
    Member
    Posted 1 year ago #

    Here is an example of how I implemented the functionality. Customize to your liking. This new functionality MAY slow your database server down if you have an extensive user list, as it parses all users to determine the current ranking at each page load. I'd be interested to hear how this works for you.

    Also, the current user is not displayed if they are in the top 10 and the first page is being displayed, the assumption being they already see themselves.

    <?php
    /*
    Template Name: Roster
    */
    	get_header();
    
    	global $wpdb, $current_date;
    	$db_prefix = $wpdb->base_prefix;
    	get_currentuserinfo();
    
    	$wpdb->query('SET @rank = 0;');
    	$listCurrentUser = $wpdb->get_results
    	(
    		'SELECT *
    		FROM (
    			SELECT
    				@rank := @rank + 1 AS rank
    				,person.*
    				,nick.meta_value AS nickname
    				,SUM(karma.meta_value) AS total_karma
    			FROM ' . $db_prefix . 'users AS person
    			LEFT JOIN ' . $db_prefix . 'usermeta as nick
    				ON person.id = nick.user_id
    				AND nick.meta_key = "nickname"
    			LEFT JOIN ' . $db_prefix . 'usermeta as karma
    				ON person.id = karma.user_id
    				AND karma.meta_key = "' . $db_prefix . '_dpa_points"
    			GROUP BY nick.meta_value
    				,person.ID
    			ORDER BY total_karma DESC
    		) AS leaderboard
    		WHERE 1 = 1
    			AND ID = ' . $current_user->ID . '
    		LIMIT 0, 1;'
    	);
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $post_per_page = intval(get_query_var('posts_per_page'));
        $offset = ($paged - 1)*$post_per_page;
    	$wpdb->query('SET @rank = 0;');
    	$listAllUsers = $wpdb->get_results
    	(
    		'SELECT SQL_CALC_FOUND_ROWS
    			@rank := @rank + 1 AS rank
    			,person.*
    			,nick.meta_value AS nickname
    			,SUM(karma.meta_value) AS total_karma
    		FROM ' . $db_prefix . 'users AS person
    		LEFT JOIN ' . $db_prefix . 'usermeta as nick
    			ON person.id = nick.user_id
    			AND nick.meta_key = "nickname"
    		LEFT JOIN ' . $db_prefix . 'usermeta as karma
    			ON person.id = karma.user_id
    			AND karma.meta_key = "' . $db_prefix . '_dpa_points"
    		GROUP BY nick.meta_value
    			,person.ID
    		ORDER BY total_karma DESC
    		LIMIT ' . $offset . ', ' . $post_per_page . ';'
    	);
    	$sql_posts_total = $wpdb->get_var( "SELECT FOUND_ROWS();" );
        $max_num_pages = ceil($sql_posts_total / $post_per_page);
        $html = '
    <table id="roster">
    	<tr>
    		<th>Rank</th>
    		<th>Avatar</th>
    		<th>Name</th>
    		<th>Rank</th>';
    	if (is_user_logged_in())
    	{
    		$html .= '
    		<th>Advancement</th>
    		<th>Email</th>';
    	}
    	$html .= '
    		<th>Member Since</th>
    	</tr>';
    	//put current user at top of each page
    	foreach ($listCurrentUser as $row)
    	{
    		if (($row->Rank > 10) || ($offset > 0))
    		{
    			$this_user = get_userdata($row->ID);
    			$html .= '
    		<tr class="current_user_top">
    			<td>' . $row->rank . '</td>
    			<td>' . get_avatar($row->ID, 39) . '</td>
    			<td>' . $this_user->nickname . '</td>
    			<td>';
    			if ( !empty( $this_user->roles ) && is_array( $this_user->roles ) )
    			{
    				foreach ( $this_user->roles as $role )
    				{
    					if (strpos($role, "bbp_") === false)
    					{
    						$html .= ucfirst(strtolower($role));
    					}
    				}
    			}
    			$html .= '</td>
    			<td>' . dpa_get_user_points( $row->ID ) . '</td>';
    			if (is_user_logged_in())
    			{
    				$html .= '
    			<td>' . $this_user->user_email . '</td>';
    			}
    			$html .= '
    			<td>' . $this_user->user_registered . '</td>
    		</tr>';
    		}
    	}
    	//get the current page of the leaderboard
    	foreach ( $listAllUsers as $row )
    	{
    		$this_user = get_userdata( $row->ID );
    		if ($row->ID == $current_user->ID)
    		{
    			$html .= '
    	<tr class="current_user">';
    		}
    		else
    		{
    			$html .= '
    	<tr>';
    		}
    		$html .= '
    		<td>' . $row->rank . '</td>
    		<td>' . get_avatar($row->ID, 39) . '</td>
    		<td>' . $this_user->nickname . '</td>
    		<td>';
    		if ( !empty( $this_user->roles ) && is_array( $this_user->roles ) )
    		{
    			foreach ( $this_user->roles as $role )
    			{
    				if (strpos($role, "bbp_") === false)
    				{
    					$html .= ucfirst(strtolower($role));
    				}
    			}
    		}
    		$html .= '</td>
    		<td>' . dpa_get_user_points( $this_user->ID ) . '</td>';
    		if (is_user_logged_in())
    		{
    			$html .= '
    		<td>' . $this_user->user_email . '</td>';
    		}
    		$html .= '
    		<td>' . $this_user->user_registered . '</td>
    	</tr>';
    	}
    	$html .= '
    </table>
    <div class="navigation">
        <div class="previous panel">' . previous_posts_link('&laquo; Previous Page',$max_num_pages) . '</div>
        <div class="next panel">' . next_posts_link('Next Page &raquo;',$max_num_pages) . '</div>
    </div>';
    	echo $html;
    	comments_template( '', true );
    	get_sidebar();
    	get_footer();
  18. Paul Gibbs
    BuddyPress Lead Developer
    Plugin Author

    Posted 1 year ago #

    Funny timing - I was looking at the best way to do SQL queries to find the ranking position:

    http://code.openark.org/blog/mysql/sql-ranking-without-self-join
    http://rpbouman.blogspot.co.uk/2009/09/mysql-another-ranking-trick.html?m=1

    :)

  19. mikebronner
    Member
    Posted 1 year ago #

    Serendipity is awesome :) Thanks! I'll improve the query and wrap it in a function to be more versatile.

  20. mikebronner
    Member
    Posted 1 year ago #

    Thank Paul for the additional references. This allowed me to significantly optimize the query and wrap it neatly in a function.

    For those using this functionality, please add the following function to your functions.php in your child theme:

    /**
     * Returns either the ranking for the current user (single row result) or for all users (limited to the current page, if not overriden).
     *
     *
     * @param bool $show_current_user Optional. If true will get the ranking for the current user only. Default is false.
     * @param int $offset Optional. If set, will start the query from a given offset record. Default is to use normal pagination offset.
     * @param int $posts_per_page Optional. If set, will change the number of records returned per page. Default is WordPress default value.
     *
     * @return array. Two-dimensional array is returned, array["restults"] holds search results, while array["total_number_of_pages"] holds the max number of pages which can be used for pagination links.
     * @since Achievements (3.2.2)
     * @author Mike Bronner <mike.bronner@gmail.com>
     */
    function dpa_get_leaderboard_rankings($show_current_user = false, $offset = null, $posts_per_page = null)
    {
    	global $wpdb;
    
    	if ($show_current_user)
    	{
    		get_currentuserinfo();
    	}
    	if (null === $posts_per_page)
    	{
    		$posts_per_page = intval(get_query_var('posts_per_page'));
    	}
    	$db_prefix = $wpdb->base_prefix;
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $posts_per_page = intval(get_query_var('posts_per_page'));
        if (null === $offset)
        {
    	    $offset = ($paged - 1) * $posts_per_page;
    	}
    	$leaderboard_query = "SELECT SQL_CALC_FOUND_ROWS
    				person.*
    				,nick.meta_value AS nickname
    				,SUM(karma.meta_value) AS total_karma
    				,FIND_IN_SET(karma.meta_value, (SELECT  GROUP_CONCAT(DISTINCT ranking.meta_value ORDER BY ranking.meta_value  DESC) FROM konb_usermeta AS ranking WHERE ranking.meta_key = 'konb__dpa_points')) as rank
    			FROM " . $db_prefix . "users AS person
    			LEFT JOIN " . $db_prefix . "usermeta as nick
    				ON person.id = nick.user_id
    				AND nick.meta_key = 'nickname'
    			LEFT JOIN " . $db_prefix . "usermeta as karma
    				ON person.id = karma.user_id
    				AND karma.meta_key = '" . $db_prefix . "_dpa_points'
    		WHERE 1 = 1";
    	if ($show_current_user)
    	{
    		$leaderboard_query .= "
    			AND ID = " . $current_user->ID;
    	}
    	$leaderboard_query .= "
    		GROUP BY nick.meta_value
    			,person.ID
    		ORDER BY total_karma DESC
    			,person.user_registered ASC";
    	if ($show_current_user)
    	{
    		$leaderboard_query .= "
    		LIMIT 0, 1;";
    	}
    	else
    	{
    		$leaderboard_query .= "
    		LIMIT " . $offset . ", " . $posts_per_page . ";";
    	}
    	$leaderboard["results"] = $wpdb->get_results($wpdb->prepare($leaderboard_query, null));
    	$sql_posts_total = $wpdb->get_var( "SELECT FOUND_ROWS();" );
        $leaderboard["total_number_of_pages"] = ceil($sql_posts_total / $posts_per_page);
    
        return $leaderboard;
    }

    Also, consider the following example to implement this functionality, again using a page template as described above:

    <?php
    /*
    Template Name: Roster
    */
    	get_header();
    
    	$listCurrentUser = dpa_get_leaderboard_rankings($current_user->ID);
    	$listAllUsers = dpa_get_leaderboard_rankings();
        $html = '
    <table id="roster">
    	<tr>
    		<th>Rank</th>
    		<th>Avatar</th>
    		<th>Name</th>
    		<th>Rank</th>';
    	if (is_user_logged_in())
    	{
    		$html .= '
    		<th>Advancement</th>
    		<th>Email</th>';
    	}
    	$html .= '
    		<th>Member Since</th>
    	</tr>';
    	//put current user at top of each page
    	foreach ($listCurrentUser["results"] as $row)
    	{
    		if (($row->Rank > 10) || ($offset > 0))
    		{
    			$this_user = get_userdata($row->ID);
    			$html .= '
    		<tr class="current_user_top">
    			<td>' . $row->rank . '</td>
    			<td>' . get_avatar($row->ID, 39) . '</td>
    			<td>' . $this_user->nickname . '</td>
    			<td>';
    			if ( !empty( $this_user->roles ) && is_array( $this_user->roles ) )
    			{
    				foreach ( $this_user->roles as $role )
    				{
    					if (strpos($role, "bbp_") === false)
    					{
    						$html .= ucfirst(strtolower($role));
    					}
    				}
    			}
    			$html .= '</td>
    			<td>' . dpa_get_user_points( $row->ID ) . '</td>';
    			if (is_user_logged_in())
    			{
    				$html .= '
    			<td>' . $this_user->user_email . '</td>';
    			}
    			$html .= '
    			<td>' . $this_user->user_registered . '</td>
    		</tr>';
    		}
    	}
    	//get the current page of the leaderboard
    	foreach ( $listAllUsers["results"] as $row )
    	{
    		$this_user = get_userdata( $row->ID );
    		if ($row->ID == $current_user->ID)
    		{
    			$html .= '
    	<tr class="current_user">';
    		}
    		else
    		{
    			$html .= '
    	<tr>';
    		}
    		$html .= '
    		<td>' . $row->rank . '</td>
    		<td>' . get_avatar($row->ID, 39) . '</td>
    		<td>' . $this_user->nickname . '</td>
    		<td>';
    		if ( !empty( $this_user->roles ) && is_array( $this_user->roles ) )
    		{
    			foreach ( $this_user->roles as $role )
    			{
    				if (strpos($role, "bbp_") === false)
    				{
    					$html .= ucfirst(strtolower($role));
    				}
    			}
    		}
    		$html .= '</td>
    		<td>' . dpa_get_user_points( $this_user->ID ) . '</td>';
    		if (is_user_logged_in())
    		{
    			$html .= '
    		<td>' . $this_user->user_email . '</td>';
    		}
    		$html .= '
    		<td>' . $this_user->user_registered . '</td>
    	</tr>';
    	}
    	$html .= '
    </table>
    <div class="navigation">
        <div class="previous panel">' . previous_posts_link('&laquo; Previous Page', $listAllUsers["total_number_of_pages"]) . '</div>
        <div class="next panel">' . next_posts_link('Next Page &raquo;', $listAllUsers["total_number_of_pages"]) . '</div>
    </div>';
    	echo $html;
    	comments_template( '', true );
    	get_sidebar();
    	get_footer();

    Please update your code if you have been using my work-around above. Let us know how it works, and please post screenshots. Maybe we can convince Paul to incorporate the function. ;-)

  21. strozzapr
    Member
    Posted 1 year ago #

    Hi! I tried to implement this last code but it does not generate any data. I do have the template showing however there are no users.

  22. mikebronner
    Member
    Posted 1 year ago #

    Hi strozzapr, can you post a link?
    How many users are in your database? How many achievements have you set up? Have you awarded any karma to any of your users?

  23. strozzapr
    Member
    Posted 1 year ago #

    The website is currently being built. The users are fake users however I've added points to some of them. There are 2 achievements set up now.

  24. mikebronner
    Member
    Posted 1 year ago #

    I really need to see the page in action to help out more. Can you post the code for the page template here?

  25. strozzapr
    Member
    Posted 1 year ago #

  26. mikebronner
    Member
    Posted 1 year ago #

    Thanks :) Can you email me the template file you are using? I'll test with it on my end and see what's going on.

    [ redacted, support is offered via the forum and not email ]

    My initial guess is that the loop isn't working of $listAllUsers["results"] as $row, but still on the old code $listAllUsers as $row.

  27. strozzapr
    Member
    Posted 1 year ago #

    I just sent you an email! :)

  28. mikebronner
    Member
    Posted 1 year ago #

    Got it :) I copied your file verbatim, and it displays correctly on my site.

    Do a var_dump() on $listCurrentUser and $listAllUsers right after they are fetched and email me those results.

  29. mikebronner
    Member
    Posted 1 year ago #

    Also, do a var_dump in dpa_get_leaderboard_rankings() right before the return statement, like so: var_dump($leaderboard_query);

    Send me those results as well.

  30. strozzapr
    Member
    Posted 1 year ago #

    I'm sorry but I'm not sure how to complete a var_dump.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic