BuddyPress Favorites in
-
Hi,
is there any way we can add the existing buddypress favorites to the blog posts?
Thanks
Regards
Mike
-
Hi,
if you can code, it won’t be a big work.
Perhaps taking the problem from another side would be a better solution ?
Each blog post has an author. Presuming you want to show the author’s favorites ? In this case, instead of re-building the fav list on the blog template, you could link to this author profile, directly on his fav tab.
I have a shortcode ready for this, in case of you want use that solution.
Dear @danbp
thank you for your kind reply.
Sorry, I’m not sure I exactly understand what do you mean.
I definitely don’t want to complicated things (if it sounded like that)… as you said, I would like to keep the Favorite in user profile – however, I don’t need people to favorite their statuses (I actually removed that with CSS) – I wish to have it in blogs – so when for example Mike post a blog “Awesome BuddyPress 😉 ” I can press Favorite – this means I’ld collect favorite blogs and see them in my profile anytime in the future 😉
This is also cool, because the notifications are there… I love this features… they are just not in the right place for me 😉Thank you very much for your help 🙂
Hummm, now it’s me who doesn’t understand !
You asked first
is there any way we can add the existing buddypress favorites to the blog postsand now you say
I wish to have it in blogs – so […] I can press FavoriteSorry if i misunderstand your request, english is not my mother language… Do you want to add a [favorite] button to each blog post ? Or do you want to remove some filters from activity favorites ?
Thank you again @danbp 🙂 & sorry for the confusion.
Yes, I do want to add a [favorite] button to each blog post – unfortunately the plugin you suggested doesn’t work – it doesn’t show any favorite button on any posts 🙁
Thanks a lot 🙂
Sorry, I haven’t tested the plugin i mentionned. You’re right it doesn’t show a button but simply display favorites differently.
OK, here is a snippet you can add to bp-custom.php which will add a Favorite button to blog posts.
Note
the function works with currrent BP version (2.6.2).
The grey side of this solution is that you have to use a child-theme and to tweak a little the way the button will show. This is very theme dependant and would not be used the same way if you use ie. Twenty Sixteen or ie. Graphene.While using 2016, you can simply echo the button on the template.
If you use a more complex theme, you could probably use an existing action hook of the theme. This means that you need a function who hooks into such a predefined placeholder.In any case, the file to modify is your theme’s single.php. Copy it into the child theme to get:
/wp-content/themes/child-theme/single.php
If you don’t see any do_action( ‘something’ ), you add the following in an appropriate place:
echo get_fav_or_unfav_button_for_post( $post );
Certainly inside the post loop, and probably below the post and before the comments.If you see some action hooks in single.php, you add this function to bp-custom:
function fav_buttons() { echo get_fav_or_unfav_button_for_post( $post ); } add_action( 'graphene_before_comment_template', 'fav_buttons' );
You need to change
graphene_before_comment_template
to the action name used by your theme.add_action( 'graphene_before_comment_template'
Hope to be clear.
And here the function for the button:
function get_fav_or_unfav_button_for_post( $post ) { global $bp, $activities_template, $post; // only show the button to logged-in users if ( ! is_user_logged_in() ) { return ''; } $activity_id = bp_activity_get_activity_id( array( 'user_id' => $post->post_author, 'type' => 'new_blog_post', 'component' => 'blogs', 'item_id' => 1, // blog_ID 'secondary_item_id' => $post->ID // post_ID ) ); if ( ! $activity_id ) { return ''; } bp_has_activities(); // update $activities_template with user's favs $old_value = false; if ( isset( $activities_template->activity->id ) ) { $old_value = $activities_template->activity->id; $activities_template->activity->id = $activity_id; } else { $activities_template->activity = (object) array( 'id' => $activity_id ); } // build the template $code = ''; $code .= '<div class="activity-meta">'."\n"; if ( ! bp_get_activity_is_favorite() ) { // if not favorited, add a "Favorite" button $code .= ' <a href="'.bp_get_activity_favorite_link( ).'" class="button fav bp-secondary-action" title="Add to my favorites">Favorite</a>'."\n"; } else { // else, add "Unfavorite" button $code .= ' <a href="'.bp_get_activity_unfavorite_link( ).'" class="button unfav bp-secondary-action" title="Remove from my favorites">Unfavorite</a>'."\n"; // Bonus button: "View all my favorites" $code .= ' <a href="'.bp_loggedin_user_domain() . 'activity/favorites/" class="button unfav bp-secondary-action">View all my favs</a>'."\n"; } // closing .activity-meta $code .= '</div>'."\n"; if ( false !== $old_value ) { $activities_template->activity->id = $old_value; } else { //$activities_template->activity = null; $activities_template->activity = (object) array( 'id' => $activity_id ); } return $code; }
And voila !
WOW, that looks hardcore Sir @danbp :))
I’ll test it later today and let you know.
Until than, THANK YOU BOSS! 🙂PS: Please don’t close. I’ll get back to you soon. Thank you 🙂
Hi @danbp,
thanks a lot! It worked :))
May I just ask you… is there any way I can add notifications to the fav action?
So it will be for example:
Mike add your article [name] to his favourites.
Thanks a lot :))
There a plugin that does Favourite notifications:
Thanks a lot @venutius :))
Do you mean that any use case should be precisely documented or would examples be enough, finally ? 🙂
Wordings can be changed in the language file.
Slugs can be changed by function.As you use a plugin, you may check inside his code and files to accomplish your customization. Or search or ask for help on his support.
Not at all dear @danbp,
I appreciate BuddyPress and its community spirit.
I just think there is no harm in asking.
Thanks a lot for the hint
Have a lovely Xmas and all the best in the new year 2017 🙂
Dear @danbp
thank you very much. It works like a charm 😉Last question, if I may and you don’t mind… 😉
Is there anyway I can avoid notifications when favouriting my own stuff? It looks a bit strange when I receive notification on that 😉
I’m using favourite function as “Saving Tool” (when I like something, I favourite it and than I can find the list in my profile).
Thanks a lot 🙂
Sorry, one more question.
I found out that if I add the article to the favourite, but the activity is deleted – the favourite is deleted too – because it’s based on favouriting the activity 🙁
This makes it probably unusable – because I wanted users to see the favourites – so they could use it as bookmarks :(((
Thanks you for all the effort. It was a good ride 😉
Hi @danbp,
I’ve used your code in 2021theme.
it doesn’t work.
so I’ve edited this section :if ( ! $activity_id ) { return 'No Activity'; }
and now in the blog post, it shows “No Activity”.
Please tell me what’s wrong.
Thanks
- You must be logged in to reply to this topic.