-
How could I display the current counts of followers, following and bookmarks in the front end.
I am currently developing my own theme and would like to know what PHP code is necessary to display total different counts for the current active/logged in user in the frontend.
example:
Bookmarks (9) | Following (89) | Followers (32)
I just need to display the actual numbers (counts).
This is fairly simple with PHP + UserPro API. Here are answers:
The UserPro API makes it so easy to access and display any functions quickly in your app / integration. First, the following/followers count:
To display the count of following for a user:
get_current_user_id() is current logged in user ID. I assume you will check that user has logged in already
PHP1<?php global $userpro; echo $userpro_social->following_count_plain( get_current_user_id() ); ?>To display the count of followers for a user:
PHP1<?php global $userpro; echo $userpro_social->followers_count_plain( get_current_user_id() ); ?>These will return the count in PLAIN format. You can customize everything else.
To show total number of pages that user has bookmarked:
You will need the updated version of Bookmarks addon API
PHP1<?php global $userpro_fav; echo $userpro_fav->bookmarks_count(get_current_user_id()); ?>You can access functions with one line using the API. A complete guide to the API will be available soon as well.
That did actually not work for me.
Do you think It matters that I got my menu wrapped with?
<?php if (is_user_logged_in() ) { //only logged in user can see this ?>
Here goes my menu and follow/bookmark counts
<?php } ?>
I just tested it and the codes worked perfectly. Please show your full code.
Could not get the code wrap to work in this bbpress forum…strange…feel free to correct the post.
Please do not paste the whole, just show me your API usage, I already had example above for you. 🙂
It’s impossible for me to post code in this forum.
Please refer to the pictures instead:
I just tested this code and it worked perfectly fine.
PHP12global $userpro_social;echo $userpro_social->following_count_plain( get_current_user_id() );I am sorry, can someone please try that code as php code in theme (with social active) to get the count of following users?
Thanks for teh confirmation 🙂 I guess it is a version issue (old version maybe)
I just updated to 1.0.53 (the latest version found on code canyon) and the error still remains.
Everything after where the php echo is inserted get’s blanked out (by the error depending on what location i put it).
I just realized now that my following and followers page gets 404’s.
This has to be contributing to the issue…
I build my theme on the bones framework btw.
Okey so after a lot of testing I got it to work on index.php and other template files.
But not in the header.php or footer.php?
Does anyone else has the same issue?
I can not get these 3 lines of code to work in the header.php (I have even tested with twentyfourteen theme)
Can someone please confirm that they where able to display follower/following and bookmarks counts in header.php
Thanks People!
You must be logged in to reply to this topic.