secret
Last active — forked from brichards/untitled.php

  • Download Gist
untitled.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
<?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++;
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.