Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
<?php
/**
* Display earned badges for a given author
*
* @param integer $author_id The user's ID, defaults to current post author
* @param string $achievement_type A specific type of achievement to list (e.g. 'badge')
* @param integer $limit Number of achievements to include
* @return string Concatenated output
*/
function custom_badgeos_get_author_achievements( $author_id = 0, $achievement_type = '', $limit = 1 ) {
// Get the post author if no specific user specified.
if ( ! $author_id ) {
global $post;
$author_id = $post->post_author;
}
// Grab the user's current achievements, without duplicates
$achievements = array_unique( badgeos_get_user_earned_achievement_ids( $author_id, $achievement_type ) );
// Setup a counter
$count = 0;
// Loop through the achievements
if ( ! empty( $achievements ) ) {
foreach( $achievements as $achievement_id ) {
// If we've hit our limit, quit
if ( $count >= $limit )
break;
// Output our achievement image and title
echo '<div class="badgeos-badge-wrap">';
echo badgeos_get_achievement_post_thumbnail( $achievement_id );
echo '<span class="badgeos-title-wrap">' . get_the_title( $achievement_id ) . '</span>';
echo '</div>';
// Increase our counter
$count++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.