Adding some cool “Call to Action” buttons to stream entries

When something happens within your BuddyPress Community, you usually want others to respond to this activity. That’s the whole core concept of Social networking. By default BuddyPress adds a “Reply” and “Favorite” button to activity stream items, and while this is cool, for some entries you would like the user to go somewhere. This simple snippet will add a additional button which points them in the right direction.

Add the following code to your Child Themes Functions.php or add it to BP-Custom.php in your plugin folder

/* Add Cool Buttons to Activity Stream Items */
function my_bp_activity_entry_meta() {
	if ( bp_get_activity_object_name() == 'blogs' && bp_get_activity_type() == 'new_blog_post' ) {?>
		<a class="view-post" href="<?php bp_activity_thread_permalink() ?>">View Blog Post</a>
	<?php }
	if ( bp_get_activity_object_name() == 'blogs' && bp_get_activity_type() == 'new_blog_comment' ) {?>
		<a class="view-post" href="<?php bp_activity_thread_permalink() ?>">View Blog Comment</a>
	<?php }
	if ( bp_get_activity_object_name() == 'activity' && bp_get_activity_type() == 'activity_update' ) {?>
		<a class="view-post" href="<?php bp_activity_thread_permalink() ?>">View Activity Status</a>
	<?php }
        if ( bp_get_activity_object_name() == 'groups' && bp_get_activity_type() == 'new_forum_topic' ) {?>
		<a class="view-thread" href="<?php bp_activity_thread_permalink() ?>">View Forum Thread</a>
	<?php }
        if ( bp_get_activity_object_name() == 'groups' && bp_get_activity_type() == 'new_forum_post' ) {?>
	    <a class="view-post" href="<?php bp_activity_thread_permalink() ?>">View Forum Reply</a>
	<?php }
}
add_action('bp_activity_entry_meta', 'my_bp_activity_entry_meta');

You’ll now have some neat buttons which call your user to action! Here’s an example for a blog post entry:
Screen shot 2011 05 17 at 7.45.30 PM 680x291 Adding some cool “Call to Action” buttons to stream entries

Credits

[bc_member name=”etiviti” size=”80″ fields=”About me,Website,Twitter Name”]

BuddyPress Hosting Guide Looking for quality BuddyPress hosting? We will guide you through all the available hosting options and help you find the best webhost for your next BuddyPress project!

Something about bowe

BuddyPress fanatic, WordPress Theme designer and MultiSite community builder. Proud co-founder of PressCrew. Loves to use awesome in every sentence. Often described as a Dutch Treehugging Hippie.

23 Responses to Adding some cool “Call to Action” buttons to stream entries

  1. Tyler May 29, 2011 at 3:24 pm #

    Say I wanted View Blog Post to be listed before Favorite. Is there a way to determine the order in which those buttons are displayed?

  2. stwc May 31, 2011 at 11:16 pm #

    Nice. Added these to my site’s activity stream — every little thing that helps users understand where and how things fit together on a BP site is very useful indeed.

  3. AllMad.org Ranting September 7, 2011 at 5:36 pm #

    Can anyone confirm that this works A-okay with BP 1.5?

  4. Acouphene October 23, 2011 at 7:00 pm #

    Same question. Anyone

  5. bowe October 26, 2011 at 12:05 pm #

    It works in BP 1.5! At least it does for me!

  6. Manish January 9, 2012 at 7:17 am #

    The code shows only links on my website, no buttons.
    How do I add the buttons like in the screenshot?

  7. Manish January 15, 2012 at 6:00 am #

    I added the css for buttons

    but there is another problem. This code seems to cut (truncate) the url if the url is very long

    if ( bp_get_activity_object_name() == ‘groups’ && bp_get_activity_type() == ‘new_forum_topic’ ) {?>
    <a class="view-thread" href="”>View Forum Thread

    <a class="view-post" href="”>View Forum Reply
    <?php }

    And then the buttons give 404

    • Bowe February 2, 2012 at 9:52 am #

      Hi Manish,

      This problem seems to be related to BuddyPress itself. The functionality that is used to create the links is present in Core..

  8. Jay Collier April 3, 2012 at 2:27 pm #

    This worked great for me with 1.5.5 and 3.3.1.

    I copied the CSS from the other buttons and added this to styles.css in my child theme:

    .activity-meta a.view-post
    {
    background: #ededed;
    background: moz-linear-gradient(top, #ffffff 0%, #e0e0e0 100%);
    background: webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#e0e0e0));
    background: -webkit-linear-gradient(top, #ffffff 0%,#e0e0e0 100%);
    background: -o-linear-gradient(top, #ffffff 0%,#e0e0e0 100%);
    background: -ms-linear-gradient(top, #ffffff 0%,#e0e0e0 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=’#ffffff’, endColorstr=’#e0e0e0′,GradientType=0 );
    background: linear-gradient(top, #ffffff 0%,#e0e0e0 100%);
    border: 1px solid #bbb;
    webkit-border-radius: 3px;
    border-radius: 3px;
    color: #555;
    outline: none;
    text-decoration: none;
    }

  9. Jay Collier April 3, 2012 at 2:28 pm #

    This worked great for me with 1.5.5 and 3.3.1.

    I copied the CSS from the other buttons and added this to styles.css in my child theme:

    .activity-meta a.view-post
    {
    background: #ededed;
    background: moz-linear-gradient(top, #ffffff 0%, #e0e0e0 100%);
    background: webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#e0e0e0));
    background: -webkit-linear-gradient(top, #ffffff 0%,#e0e0e0 100%);
    background: -o-linear-gradient(top, #ffffff 0%,#e0e0e0 100%);
    background: -ms-linear-gradient(top, #ffffff 0%,#e0e0e0 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=’#ffffff’, endColorstr=’#e0e0e0′,GradientType=0 );
    background: linear-gradient(top, #ffffff 0%,#e0e0e0 100%);
    border: 1px solid #bbb;
    webkit-border-radius: 3px;
    border-radius: 3px;
    color: #555;
    outline: none;
    text-decoration: none;
    }

  10. O'Ryan McEntire April 6, 2012 at 10:53 pm #

    I wonder if one could use this to build a totally customized activity stream.

    I’ve been trying to simplify the stream that shows up on my users profiles so i can just add it to their main profile page as a mini widget.

    something like :

    posted in the forums
    5mins ago

    replied to a comment
    10mins ago

    liked a comment
    2 days ago

    hmm…

  11. Bichoupanycq April 18, 2012 at 7:45 am #

    Paperbee

  12. Jermaulcevala April 18, 2012 at 10:49 am #

    Paperbee

  13. Daniel Schulz-Jackson May 19, 2012 at 5:21 pm #

    [bc_member name=”etiviti” size=”80″ fields=”About me,Website,Twitter Name”] is showing up

  14. Magnus June 25, 2012 at 1:23 pm #

    Hi!

    Excellent trick, very useful for adding extra clarity to how the activity stream works, especially with blog posts and discussion forums. Now, if I would want to re-arrange the order of the activity stream buttons (as some other people also have asked above), I would have to modify the corresponding template file, right?

    Thanks and I’d love to see more tricks here! ;)

  15. Magnus June 28, 2012 at 9:04 pm #

    Hi again!

    The extra buttons are great. However, if I click on “View Activity Status” that button is still visible on the page that only shows the single activity status. How would I remove this since it seems odd to link to the current page there?

    Thanks!

  16. Allen February 14, 2013 at 3:52 pm #

    I have a problem here. I use bbpress 2 and the button doesn’t show when a new forum topic is created. I use sitewide forums not group forums.

    My guess is i need to change groups to something else in this:

    if ( bp_get_activity_object_name() == ‘groups’

    I tried ‘forums’ , ‘bp-forums’ … and several more but it doesn’t work?

    What’s the correct object name for sitewide forums?

  17. Allen February 14, 2013 at 4:32 pm #

    Found the solution. Here’s the working code for the latest version of buddypress and bbpress (sitewide):

    if ( bp_get_activity_object_name() == ‘bbpress’ && bp_get_activity_type() == ‘bbp_topic_create’ ) {?>
    <a class="button" href="”>View Topic

    <a class="button" href="”>View Reply
    <?php }

    • bowe February 26, 2013 at 7:44 pm #

      Thanks Allen! Would it be possible if you’d post your edit as a gist (gist.com) or snippi (http://snippi.com/). I can then update the post with your updated code :-)

  18. Jay Colliery Collier July 15, 2013 at 5:16 pm #

    Appears to not be working with BP 1.6, which is too bad. This was great.

  19. Magnus September 20, 2013 at 10:03 am #

    Any updates on this? Tried to implement Allens fix above (using BuddyPress 1.8.1 and WP 3.6.1) but no luck. Loved these small buttons which helped users understand and view the forums easier.

  20. Magnus October 22, 2013 at 8:12 pm #

    Any updates on this? Am running BuddyPress 1.8 and miss the button to view the topic in group forums from the activity stream.

  21. Magnus November 25, 2013 at 6:12 pm #

    Thanks Allen! The above code works for new forum posts. For forum replies (using the standalone bbPress plugin) the activity_type should be bbp_reply_create I think.

Leave a Reply