Add the follow button manually in a template file
-
Is it possible to add the follow button manually in a random template file?
-
Please read this wiki article:
https://github.com/r-a-y/buddypress-followers/wiki/Add-a-follow-button-on-a-regular-WP-pageThanks 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.
You have a call to
the_author_ID()
, which is not listed in my wiki article. I useget_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 )
Thanks for your reply.
Yes, I changed theget_the_author_meta( 'ID' )
because it didn’t work. I tried both of your suggestions, but still no output. No html at all.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.
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.
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.
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?
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://www.ads-software.com/support/topic/ajax-doesnt-respect-link-class-param?replies=3#post-6018349
- The topic ‘Add the follow button manually in a template file’ is closed to new replies.