Advertisement
designbymerovingi

CUSTOM BADGE CODE (BADGE IMAGES)

Aug 10th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. /**
  2.  * List all Badges based on their badge_type.
  3. */
  4.  
  5. function get_list_types_badges( $type ) {
  6.  
  7.     global $post;
  8.  
  9.     $args = array(
  10.         'order' => 'ASC', // ascending order, 1,2,3 (oldest post first)
  11.         'post_type' => 'mycred_badge', // search in the post type "mycred_badge"
  12.         'badge_type' => $type, // only list the badges assigned to the badge type entered
  13.         'post_status' => 'publish' // only list those who are publish, no drafts
  14.     );
  15.  
  16.     $myposts = get_posts( $args );
  17.  
  18.     echo '<ul class="list-badges">';
  19.     foreach ( $myposts as $post ) : setup_postdata( $post );
  20.  
  21.         echo '<li>';
  22.             echo check_badge_status();
  23.             $img_url = get_post_meta( get_the_ID(), 'main_image', true );
  24.             // myCRED 1.7+ (badge images are no longer connected via a URL but an attachment ID)
  25.             if ( is_numeric( $img_url ) )
  26.                 $img_url = wp_get_attachment_url( $img_url );
  27.             // check if the custom field has a value
  28.             if( ! empty( $img_url ) ) {
  29.             echo '<img class="badge_id-'.get_the_ID().'" src="'.$img_url.'" alt="'.get_the_title().'" />';
  30.             }
  31.             echo '</div>';
  32.  
  33.             echo '<h5>'.get_the_title().'</h5>';
  34.             echo '<span>( ' .mycred_count_users_with_badge( get_the_ID() );
  35.             echo ' / ';
  36.             echo count_all_my_users(). ' )</span>';
  37.         echo '</li>';
  38.     endforeach;
  39.     echo '</ul>';
  40.     wp_reset_postdata();
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement