BuddyDev

Search

[Resolved] Display Buddypress current user amount of Followers

Tagged: 

  • Participant
    Level: Initiated
    Posts: 20
    VITOR MATOS on #47618

    like the question here https://buddydev.com/support/forums/topic/display-buddypress-users-by-amount-of-followers/#post-47617, but how only show as a NUMBER of the total follower count from the current user to i place in a shortcode to output on a post for example?

  • Participant
    Level: Initiated
    Posts: 20
    VITOR MATOS on #47619

    Obs: i need this to show this count on a post for logged and guest users

  • Participant
    Level: Initiated
    Posts: 20
    VITOR MATOS on #47620

    i place this code to bp-custom.php but it only show on the user profile and if logged-in, i need to guest user too! and i need a method to display the count to input in blog post

    
    <?php
     /**
     * Add a "Followers (X)" tab to the members directory.
     *
     * This is so the logged-in user can filter the members directory to only
     * users that the current user is following.
     *
     * @uses bp_follow_total_follow_counts() Get the following/followers counts for a user.
     */
    function bpfollow_add_followers_tab() {
    
    	if ( ! is_user_logged_in() ) {
    		return;
    	}
    
    	$count = bp_follow_get_the_followers_count();
    
    	if ( empty( $count ) ) {
    		return;
    	}
    ?>
    
    	<li id="members-followers"><a>"><?php printf( __( 'My Followers <span>%d</span>', 'buddypress-followers' ), esc_html( $count ) ) ?></a></li>
    
    <?php
    }
    add_action( 'bp_members_directory_member_types', 'bpfollow_add_followers_tab' ); 
    ?>
    
    • This reply was modified 1 year, 11 months ago by VITOR MATOS.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #47623

    Hello Vitor,

    Thank you for the posting. As per my understanding, you want to show the follower count of the author on a single post.

    Please let me know

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 20
    VITOR MATOS on #47637

    Hello Ravi,
    Yes, i want to place this %followers_number% from the buddyboss/bp function/hook (not the r-a-y plugin) to a post single template (showing current author followers), because the alternative plugin are crashing here, and i just need this output function

    example:
    https://prnt.sc/Uc8CX8vKTADW

    • This reply was modified 1 year, 11 months ago by VITOR MATOS.
    • This reply was modified 1 year, 11 months ago by VITOR MATOS.
  • Keymaster
    (BuddyDev Team)
    Posts: 24599
    Brajesh Singh on #47643

    Hi,
    Here is your code.

    Please feel free to modify as you need

    
    <?php
    /**
     * Shows followers count of the given user or the author of current post if used inside a post
     *
     * Use: [bb-followers-count]
     * Optional user_id=numeric user id. It will use post author if not specified.
     */
    function bbf_followers_count_shortcode( $atts = array() ) {
    	if ( ! class_exists( 'BP_Activity_Follow' ) ) {
    		return '';
    	}
    
    	$atts = shortcode_atts( array(
    		'user_id' => 0,
    	), $atts, 'bb-followers-count' );
    
    	if ( $atts['user_id'] ) {
    		$user_id = absint( $atts['user_id'] );
    	} elseif ( in_the_loop() ) {
    		$user_id = get_post( get_the_ID() )->post_author;
    	}
    
    	if ( empty( $user_id ) ) {
    		return '';
    	}
    
    	$counts = BP_Activity_Follow::get_counts( $user_id );
    
    	return $counts['followers'];
    }
    
    add_shortcode( 'bb-followers-count', 'bbf_followers_count_shortcode' );
    
    

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 20
    VITOR MATOS on #47648

    Hey Brajesh,
    taking advantage of the question about the follow output, how i also insert A BUTTON TO FOLLOW in this same single-post-template for the current author

    just like this
    https://prnt.sc/crKvdE2R9_W1

    • This reply was modified 1 year, 11 months ago by VITOR MATOS.
  • Keymaster
    (BuddyDev Team)
    Posts: 24599
    Brajesh Singh on #47650

    Hi,
    Since you are using BuddyBoss, The button does not work. So, my suggestion is to not have it or request BuddyBoss to allow the buttons to work outside the default loop/profile.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 20
    VITOR MATOS on #47652

    Ohh, I see, thank you for your help so far, thank you very much for your attention Brajesh!

    • This reply was modified 1 year, 11 months ago by VITOR MATOS.
  • Keymaster
    (BuddyDev Team)
    Posts: 24599
    Brajesh Singh on #47680

    You are welcome.

The topic ‘ [Resolved] Display Buddypress current user amount of Followers’ is closed to new replies.

This topic is: resolved