1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Show badgeos achievements under avatar in bbpress

Discussion in 'WordPress' started by Divvy, Sep 9, 2017.

  1. #1
    Hello guys,

    Anyone here familiar with badgeos, buddypress and bbpress?

    If yes, maybe someone can help me.

    I have found this code to place badges (achievements) under user avatar in bbpress:

    add_filter( 'bbp_get_reply_author_link', 'my_append_badges_via_filter', 10, 2 );
    
    function my_append_badges_via_filter($author_link = '', $args) {
    
        # Needed to get the user ID of the person intended to be displayed.
        $user_id = bbp_get_reply_author_id( $args['post_id'] );
        #Construct your output here.
        $badge_output = '';
    
        $achievements = badgeos_get_user_achievements( array( 'user_id' => $user_id ) );
        if ( !empty( $achievements ) ) {
                $badge_output .= '<div class="achievements">';
            foreach ( $achievements as $achievement ) {
                            if($achievement->post_type != 'badges')
                                continue;
                $badge_output .= '<div class="achievement achievement-' . $achievement->post_type . '">';
                //echo '<h2>' . get_the_title( $achievement->ID ) . '</h2>';
                $badge_output .= get_the_post_thumbnail( $achievement->ID, 'thumbnail', array('title'=>get_the_title( $achievement->ID ) ) );
                //echo __( 'Earned on: ', 'text-domain' ) . date( get_option( 'date_format' ), $achievement->date_earned ) ;
                $badge_output .= '</div>';
            }
                $badge_output .= '</div>';
      }
       
        return  $author_link . $badge_output;
    }
    PHP:
    Does anyone know how to add a link in badges to user achievements tab page?

    That code is not perfect. Because is not showing badges only under avatar, is also showing at:
    – forums main page
    – forum page
    – above topic (information bar)

    Any idea how to fix this too? :)

    Thank you in advance guys!

    ------------------------------------
    EDIT:

    To make badge smaller I added this CSS code:

    .achievement.achievement-badges{width:40px;}
    Code (markup):
    To prevent badges to show in:
    – forums main page
    – forum page

    I added the following CSS code:

    .forum .achievement.achievement-badges{display:none;}
    Code (markup):
    Now the only thing that I need is to add a link in badges to user achievements page.
    For example, using buddypress, my url to user achievements page is:
    http://domain.com/members/user/achievements/
    Code (markup):
    Any idea how to do this?

    Thanks in advance :)
     
    Last edited: Sep 9, 2017
    Divvy, Sep 9, 2017 IP
  2. Divvy

    Divvy Well-Known Member

    Messages:
    781
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    Hello guys,

    The code above is working perfectly, but the badges doesn't have a link to user achievements tab page.

    For example, using buddypress, my url to user achievements page is:
    http://domain.com/members/user/achievements/
    Code (markup):
    Badgeos Docs: http://badgeos.org/api/

    Any idea how to do this?

    Thank you in advance :)
     
    Divvy, Sep 13, 2017 IP