Skip to:
Content
Pages
Categories
Search
Top
Bottom

Show favourite count after each activity?

  • Avatar of Ousep
    ousep
    Participant

    @ousep

    I’ve put this into my bp-custom.php:

    function my_show_favorite_count() {
    $my_fav_count = bp_activity_get_meta( $_POST['id'], 'favorite_count' );
    echo $my_fav_count;
    }
    add_action( 'bp_activity_entry_meta', 'my_show_favorite_count' );

    to get the total number of times an activity has been favourited…

    But, nothing shows up… Am I missing something here?

Viewing 4 replies - 26 through 29 (of 29 total)
  • Avatar of tse11
    tse11
    Participant

    @tse11

    Hey there, I know this is an old post but the code actually works in BP 1.8. The only minor issue is that the count displays to the far right of the actual favorite link. Any ideas on how to get this next to Favorites like this: Favorite(10) instead of: Favorite         delete (10) would be wayy appreciated!

    Avatar of tse11
    tse11
    Participant

    @tse11

    So I answered my own question by just experimenting. I figure I go ahead and let everyone who is interested in this know how I got everything working. I used the following code and placed it in my bp-custom.php

    function my_favorite_count() {
    
    $my_fav_count = bp_activity_get_meta( bp_get_activity_id(), 'favorite_count' );
    
    if ($my_fav_count >= 1) : {
    
    if (is_user_logged_in()) : { echo '<span class="fav-count">('.$my_fav_count.')</span>';
    
    }
    
    endif;
    
    }
    
    endif;
    
    }
    
    add_action( 'bp_activity_entry_meta', 'my_favorite_count' );

    I added a span class in this code as you can see, and that is how I managed to display the count directly next to favorites button (or link).

    I added this to my css:

    .fav-count {
    margin-left: -15px !important;
    }

    You may have to play with it to get the margin just right, hope this helps someone.

    Avatar of deepbevel
    deepbevel
    Participant

    @deepbevel

    @ousep, your code still works after all these years.. it shows the count after the favorite button, perhaps not the most elegant solution (in the button, like the comments count, would be ideal) but it works! thank you!

    Avatar of Florence Baby
    Florence Baby
    Participant

    @okuleyeflo

    Hi, @tse11, @deepbevel, @ousep

    did anyone know a better solution for this in BP 2.0.

    The above code is still working but it is not ajax. you have to reload the page to see the count.

    Regards

Viewing 4 replies - 26 through 29 (of 29 total)

You must be logged in to reply to this topic.