Points and Achievements Display In bbpress user profile and forum
-
This is what I cobbled together from another post to show badges and points earned in the user profiles and in the forum replies for BBpress. I thought I would share it because I see the question being asked fairly often, but most replies talk about buddypress. Those solutions work here if you call some different variables.
bbp_get_displayed_user_id() is the crux. That was what allowed me to get the correct id in a usable fashion. This code lets me display the number of points on the user profile. This is what I have in my custom template of user-profile.php for bbpress.
<?php dpa_get_user_points(bbp_get_displayed_user_id()) ?>
To get the badges and achievements to show took a little more, but it was a WP_Querythat I put together from someone else’s topics here in the forum.
<!-- Display Points earned--> <p class="bbp-user-reply-count">Points Earned: <?php echo dpa_user_points( bbp_get_displayed_user_id() ); ?></p> <!-- Display Achievements With Images--> <h2>Badges Earned</h2> <?php // WP_Query arguments $args = array ( 'post_type' => 'dpa_progress', 'post_status' => 'dpa_unlocked', 'author' => bbp_get_displayed_user_id(), 'order' => 'DESC', 'orderby' => 'date', 'nopaging' => true ); // The Query $badges = new WP_Query( $args ); ?> <!-- Display Achievements earned--> <?php while ($badges->have_posts()) : $badges->the_post(); ?> <div style="float:left; max-width:250px;margin:15px;"> <h4 style="margin:0 auto;"> <?php esc_attr( the_title() ); ?></h4> <a href="<?php echo get_permalink($post->post_parent); ?>" target="_blank" title="<?php esc_attr( the_title() ); ?>"> <?php echo get_the_post_thumbnail($post->post_parent,'thumbnail'); ?> </a> </div> <?php endwhile; ?> <?php wp_reset_postdata(); ?>
This is what I do in bbpress in the loop-single-reply.php custom template in my theme folder so that it shows a minimized version for each forum reply or topic. Same thing as above, but I use bbp_get_reply_author_id() inside the dpa_get_user_points to display the number of earned points and achievements for each forum author.
<!-- Display Points earned--> <?php echo '<p class="bbb-author-shins">Points: '. dpa_get_user_points(bbp_get_reply_author_id()) .'</p>' ?> <!--Achievements--> <p><b>Badges</b></p> <?php // WP_Query arguments $args = array ( 'post_type' => 'dpa_progress', 'post_status' => 'dpa_unlocked', 'author' => bbp_get_reply_author_id(), 'order' => 'DESC', 'orderby' => 'date', 'nopaging' => true ); // The Query $badges = new WP_Query( $args ); ?> <?php while ($badges->have_posts()) : $badges->the_post(); ?> <a>post_parent); ?>" target="_blank" title="<?php esc_attr( the_title() ); ?>"> <?php echo get_the_post_thumbnail($post->post_parent, array( 30, 30)); ?> </a> <?php endwhile; ?> <?php wp_reset_postdata(); ?> <!--End achievement display-->
I figured this might be useful to anyone trying the same thing.
- The topic ‘Points and Achievements Display In bbpress user profile and forum’ is closed to new replies.