Skip to:
Content
Pages
Categories
Search
Top
Bottom

Highlight specific post categories in the activity stream?


  • hypergripe
    Participant

    @hypergripe

    I’ve searched for a way to do this and can’t find anything in here, or the BP documentation…

    Our blog has 2 categories – A & B.

    In the activity stream, we would like to be able to display post updates from category A with a green background, and display posts from category B with a red background.

    We’ve tried wp_category and even bp_category, which has lead us here.

    Any ideas on how do we determine the post category in the activity stream, so we can create a css class for it?

    Thanks in advance!

Viewing 8 replies - 1 through 8 (of 8 total)

  • hypergripe
    Participant

    @hypergripe

    Bump. Any ideas anyone?


    Xevo
    Participant

    @xevo

    You’d have to add the class to the post before it gets dumped into the database, you can’t sort it after, since buddypress activity stream does not add this kind of information, and the html is also inside the database to reduce queries and load time.

    Try finding the function that adds new posts into the activity stream.


    hypergripe
    Participant

    @hypergripe

    Thx @Xevo, we are trying to add the class using this code:

    class="<?php if ( in_category(1)) { echo "cat_a"; } elseif ( in_category(2)) { echo "cat_b"; } else { echo 'cheese';} ?>"

    Obviously not working, but as you say, BP doesn’t seem to pass the category with the rest of the post info.

    Any ideas how to create a function to do that?


    Boone Gorges
    Keymaster

    @boonebgorges

    There are two options. One is to hook a function to bp_blogs_new_blog_post that takes the post content and uses bp_activity_update_meta to add the category to the activity meta table. Then you’d have to build a function that does something like what you want in_category to do, which would work by using bp_activity_get_meta to get the category that you recorded when the blog post was saved.

    The other option is to hook a filter to bp_has_activites, which would loop through all of the returned activities, identify the new blog posts by the activity action, and when it found one, load the entire blog post in order to get the categories. In order to load the blog post, you’d probably have to switch_to_blog and then use get_post. This is really database intensive and should probably be avoided – the first option is probably the best (though it won’t be retroactive).


    hypergripe
    Participant

    @hypergripe

    Thanks for your reply @boonebgorges, it’s greatly appreciated;

    I like option one, but I’m not that proficient at coding…. as you’ll see. lol!

    How do you “hook a function to bp_blogs_new_blog_post that takes the post content and uses bp_activity_update_meta to add the category to the activity meta table”?

    Then, how do you “build a function that does something like what you want in_category to do, which would work by using bp_activity_get_meta to get the category that you recorded when the blog post was saved”?


    hypergripe
    Participant

    @hypergripe

    I’m still stuck on this…

    Can anyone suggest a code snippet that might get me started?

    Thx so much in advance!


    Tore
    Participant

    @toregus

    If you don’t know coding at all, this is probably to hard for you. Just saying.


    Tore
    Participant

    @toregus

    I’d try to hire a coder to do it for you if you have funds instead of coding skills.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Highlight specific post categories in the activity stream?’ is closed to new replies.
Skip to toolbar