Code Snippets

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”]

About Bowe Frankema

 Adding some cool “Call to Action” buttons to stream entries Building communities on BuddyPress is something I’m very passionate about. The decision to focus exclusively on BuddyPress projects over the last few years inspired me to share back some of the things I've learned here on BP-Tricks! You can find me on WordCamps & BuddyCamps across the globe and on Twitter! Follow me on Twitter

I'm constantly updating my BuddyPress Hosting Guide and SiteGround and WPEngine
have proven to be a great fit for hosting your BuddyPress community.

Need some help finding the perfect host? Check out my in-depth BuddyPress Hosting guide!

Discussion

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

  1. 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.

  2. 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

  3. 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;
    }

  4. 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;
    }

  5. 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…

  6. 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! ;)

  7. 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!

  8. 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?

  9. 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 }

  10. 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.

  11. 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

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>