Badges

Home Forums Community Badges

This topic contains 1 reply, has 2 voices, and was last updated by  Gabriel Merovingi 1 year, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #18700

    SDCOM
    Newbie

    How can I have my badges show up when a user comments on posts and on the BuddyPress groups and activity stream?

    #18817

    Gabriel Merovingi
    Legend

    For showing badges in comments, you will need to insert the mycred_my_badges shortcode into your comments template. Depending on how your theme handles / displays post comment this can be done a lot of different ways. So first you will need to find out how your theme presents comments, and see if you can insert the shortcode. The trick is that you will need to get the Users ID in order to show a specific users badges. Otherwise anywhere you insert the shortcode without an ID will show your badges and not the commenters.

    For BuddyPress groups is far more tricky since badges are given to users and not groups. There is no shortcode in myCRED that shows badges for a large group of people so this would need to be custom built to your specifications.

    For the activity stream however it is pretty easy and only require a minor code snippet like this:

    add_action( 'bp_activity_entry_content', 'mycredpro_insert_badge_in_activity' );
    function mycredpro_insert_badge_in_activity() {
    
    	global $activities_template;
    
    	if ( ! empty( $activities_template->activity->user_id ) ) {
    
    		echo do_shortcode( '[mycred_my_badges user_id="' . $activities_template->activity->user_id . '"]' );
    
    	}
    
    }
    

    This code snippet goes into your child theme’s functions.php file and will insert the users badges after the content.

    #32413

    rpetitto
    Senior Member

    Could this be tweaked to display the rank instead of badge? Would also love an entry when a user promotes in rank!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

Last edited February 3, 2016