mycred_best_user

Codex / mycred/balance / Shortcodes / mycred_best_user

Description

This shortcode allows you to present the “best” user according to their total accumulated balance or by one or more references. The shortcode by default shows the users name and avatar but this can be customized to show the details you want.

The shortcode will present by default the users avatar and display name, but this can be customized by wrapping the shortcode around custom HTML. See below for available template tags you can use.

Available since version 1.6.7

Shortcode Attributes

Attribute Type Required Default Description
ref string No - Optional reference(s) to base the best user of. Can either be one particular reference or a comma separated list of references.
from string No - Optional date from when log entries should be calculated. Can be either a well formatted date or keywords like "now" or "today". See strtotime for further information on available options.
until string No - Used in combination with "from" the end date of calculations. Can be either a well formatted date or keywords like "now" or "today". See strtotime for further information on available options.
types string No mycred_default Option to limit calculation to a particular point type or a comma separated list of point types.
nothing string No "No user found" Text to show if no user was found to be the best based on your shortcode setup.
order string No DESC The sort order to use in calculations. Can either be "DESC" for descending or "ASC" for ascending.
avatar int No 50 The size of the avatar image without "px".

CSS Styling

.mycred-best-user { }
.mycred-best-user-no-results { }

Available Template Tags

  • %display_name% – replaced with the users display name
  • %first_name% – replaced with the users first name
  • %last_name% – replaced with the users last name
  • %user_email% – replaced with the users email
  • %user_login% – replaced with the users username
  • %avatar% – replaced with the users avatar
  • %total% – replaced with the total calculated points amount
  • %total_abs% – replaced with the total calculated points amount and converted it into a positive number. Use this if you add up negative values but want to show a positive value.
  • %count% – replaced with the total count of log entries found for this result

Examples

Example 1: Show the best user based on who has received most points for approved comments.

[mycred_best_user ref="approved_comment"]

Example 2: Show the user who has gained most points from January 1st 2014 until now. Will calculate all instances no matter what point types there exist.

[mycred_best_user from="2014-01-01" until="now"]

Example 3: Show the user who has spent most points in the store. Note that purchases are stored as a negative value which means we need to reverse the order or the user who spent least will show up.

[mycred_best_user ref="woocommerce_payment" order="ASC"]

Example 4: Show the user who has gained most points from the default point type and a custom point type.

[mycred_best_user types="mycred_default,my_custom_type"]

Example 5: Show the user who has gained most points no matter which point type is used, and adjust the template to only show their avatar and nothing else.

[mycred_best_user]
<div class="mycred-best-user text-center">%avatar%</div>
[/mycred_best_user]

Last edited June 23, 2016