r-a-y / buddypress-followers

Follow users on your BuddyPress site. Similar to Twitter!
http://wordpress.org/plugins/buddypress-followers/
74 stars 39 forks source link

Following / Followers count on user profile #109

Closed jvp92 closed 4 years ago

jvp92 commented 5 years ago

I was wondering if it there is any way to display the "following" and "followers" count on each respective tab in the user´s profile navigation.

I found this article where it seems to explain the function for that: https://github.com/r-a-y/buddypress-followers/wiki/Get-the-following-or-followers-count-for-a-user

But after placing it on bp-custom.php or functions.php still not getting the desired result.

maxledoux commented 5 years ago

@jvp92

Yeah, that would have to go in your template file where you want the count to appear. To make it cleaner in the template, put this in your bp-custom.php file:

function get_custom_bp_followers_count($user_id, $show_following = true) {
    if ( function_exists( 'bp_follow_total_follow_counts' ) ) :
        $count = bp_follow_total_follow_counts( array(
            'user_id' => $user_id
        ) );
        if ($show_following) {
            return $count['following'];
        } else {
            return $count['followers'];
        }
    endif;
}

Then put this in your template file where you want to show the number of users the displayed user is following:

$user_id = bp_displayed_user_id;
echo get_custom_bp_followers_count($user_id, true);

Just change true to false to show number of followers the displayed user has. I didn't test this, but it should work in BP template files (like on a user profile). If you want to show it on the WP side like in author meta on a regular post, then you'd just have to fetch the $user_id differently.

jvp92 commented 5 years ago

Many thanks @maxledoux.

I placed the function in my bp-custom.php file.

But I couldn´t figure out the template to display the count. I tried placing $user_id = bp_displayed_user_id; echo get_custom_bp_followers_count($user_id, true); on the members-loop.php and the profile-loop.php but still didn´t get any result.

maxledoux commented 5 years ago

I guess the question is, where are you trying to put it?

jvp92 commented 5 years ago

I am trying to place it on the main tab navigation of member´s profile, so whenever I visit "my" profile or other user profile I will see something like this:

... Activity Profile Friends (5) Following (X) Followers (X) ...

Being X the number of following / followers the user has.

The question would be, in which template file would I need to place $user_id = bp_displayed_user_id; echo get_custom_bp_followers_count($user_id, true); in order to make this count appear (X) on the main tab navigation of all members?

maxledoux commented 5 years ago

buddypress-followers plugin already does put the following/followers count in the navigation tabs. If you're not seeing the counts then you have some conflict from another plugin or your theme.

See bp-followers-core.php line 136, public function setup_nav( $main_nav = array(), $sub_nav = array() ), lines 148 - 166.

jvp92 commented 5 years ago

Hey @maxledoux ,

Thanks for the feedback. I think I figured out part of the problem: At the hooks.php of the plugin, in the lines 43 and 54, the decimal counter (%d) is set between a <span>, that once removed it ends up displaying the count for both the following and the followers at their respective tabs.

However I´m trying to figure out now how to display this count as the style of my theme ... Even wondering if that could be possible...

maxledoux commented 5 years ago

Sounds like probably your theme has a display:none or opacity: 0 or some such CSS rule that is hiding that <span>. Did you do inspect element on the <span> in your browser to see what style is being applied to it?

You shouldn't remove the <span>. I believe the plugin uses it for javascript to update the number in some scenarios.

jvp92 commented 5 years ago

Hi @maxledoux

Sorry for being absent. Yeah I finally found the way! As you pointed, it was related with the class of my theme. I just changed the class to the according one with the theme and is now displaying in the right way.

Thanks for you help :)

maxledoux commented 5 years ago

If you changed the class in the plugin file that will get reverted next time there’s a plugin update. It would be better to change the class in your theme. If you have a commercial theme that receives updates then I hope you have a child theme for modifications.

jvp92 commented 5 years ago

That’s completely fine @maxledoux 👍 I made the changes in the child. Thank you!

Kikismedia commented 5 years ago

Hello please I need help I want to display my buddy press followers and following count on my theme header like this followers (1) following (1) please how can I do it I need urgent help