Support » Plugin: BuddyPress Follow » Add the follow button manually in a template file

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author r-a-y

    (@r-a-y)

    Thread Starter Wnd

    (@wnd)

    Thanks for your reply!

    I already found and tested that article. Problem is that it didn’t show the button ar any html in my template file.

    I’ve added this code inside a loop like this:

    <?php if (have_posts()) : while (have_posts()) : the_post();?>
    
    <?php
         if ( function_exists( 'bp_follow_add_follow_button' ) ) :
            if ( bp_loggedin_user_id() && bp_loggedin_user_id() != get_the_author_meta(the_author_ID()) ) {
                   bp_follow_add_follow_button( array(
                       'leader_id'   => get_the_author_meta(the_author_ID()),
                       'follower_id' => bp_loggedin_user_id()
                   ) );
               }
          endif;
    ?>
    
    <?php endwhile; endif; ?>

    The output is nothing. Am I doing something wrong?

    Thanks for your help.

    Plugin Author r-a-y

    (@r-a-y)

    You have a call to the_author_ID(), which is not listed in my wiki article. I use get_the_author_meta( 'ID' ).

    Doesn’t get_the_author_meta( 'ID' ) work?

    If that doesn’t work, try this:

    get_the_author_meta( 'ID', get_post()->post_author )

    Thread Starter Wnd

    (@wnd)

    Thanks for your reply.
    Yes, I changed the get_the_author_meta( 'ID' ) because it didn’t work. I tried both of your suggestions, but still no output. No html at all.

    Plugin Author r-a-y

    (@r-a-y)

    Try replacing get_the_author_meta( 'ID' ) with:

    get_the_author_meta( 'ID', $post->post_author )

    or:

    $post->post_author

    Remember that you have to replace both spots in the code.

    Thread Starter Wnd

    (@wnd)

    Still no output. Nothing happened. I tried the follow codes inside the loop:

    1.

    <?php
                            if ( function_exists( 'bp_follow_add_follow_button' ) ) :
                                if ( bp_loggedin_user_id() && bp_loggedin_user_id() != get_the_author_meta( 'ID' ) ) {
                                    bp_follow_add_follow_button( array(
                                        'leader_id'   => get_the_author_meta( 'ID' ),
                                        'follower_id' => bp_loggedin_user_id()
                                    ) );
                                }
                            endif;
                            ?>

    2.

    <?php
                            if ( function_exists( 'bp_follow_add_follow_button' ) ) :
                                if ( bp_loggedin_user_id() && bp_loggedin_user_id() != get_the_author_meta( 'ID', get_post()->post_author ) ) {
                                    bp_follow_add_follow_button( array(
                                        'leader_id'   => get_the_author_meta( 'ID', get_post()->post_author ),
                                        'follower_id' => bp_loggedin_user_id()
                                    ) );
                                }
                            endif;
                            ?>

    3.

    <?php
                            if ( function_exists( 'bp_follow_add_follow_button' ) ) :
                                if ( bp_loggedin_user_id() && bp_loggedin_user_id() != get_the_author_meta( 'ID', $post->post_author ) ) {
                                    bp_follow_add_follow_button( array(
                                        'leader_id'   => get_the_author_meta( 'ID', $post->post_author ),
                                        'follower_id' => bp_loggedin_user_id()
                                    ) );
                                }
                            endif;
                            ?>

    4.

    <?php
                            if ( function_exists( 'bp_follow_add_follow_button' ) ) :
                                if ( bp_loggedin_user_id() && bp_loggedin_user_id() != $post->post_author ) {
                                    bp_follow_add_follow_button( array(
                                        'leader_id'   => $post->post_author,
                                        'follower_id' => bp_loggedin_user_id()
                                    ) );
                                }
                            endif;
                            ?>

    Thanks for your help.

    Plugin Author r-a-y

    (@r-a-y)

    Silly question, but are you checking for the button if you are the author of the post and you are logged-in?

    If so, the button will not show up. It will only show up if you are not the author of the post.

    Thread Starter Wnd

    (@wnd)

    Holy sh^t! I’m feeling so stupid right now! I was logged in as the author. *Facepalm* Sorry for wasting your time bro. It works like a charm 😉

    Is it possible to not refesh the page whne using the custom button?

    Plugin Author r-a-y

    (@r-a-y)

    Is it possible to not refesh the page whne using the custom button?

    You’ll need to write some JS to target the button on your custom page for AJAX to take effect.

    See the latter portion of this comment:
    https://wordpress.org/support/topic/ajax-doesnt-respect-link-class-param?replies=3#post-6018349

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Add the follow button manually in a template file’ is closed to new replies.