Skip to:
Content
Pages
Categories
Search
Top
Bottom

Replace Activity Stream blog excerpt with the_excerpt

Viewing 25 replies - 1 through 25 (of 41 total)
  • hmm, well i was going to suggest using the filter…

    in bp_blogs_record_post
    'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink )

    which calls bp_blogs_record_activity but it does not pass the untouched content to tweak to your liking.
    $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ) ;

    It’s bp_create_excerpt() that’s killing me.

    If I could replace (or change) that to check for the existence of an excerpt and, if found, spit THAT back, it’d be perfection.


    r-a-y
    Keymaster

    @r-a-y

    Isn’t it possible to grab the excerpt based on &$post?
    $post->post_excerpt.

    Sample code:
    http://pastebin.com/s9PajKjU

    Disclaimer: Untested ;)

    [EDIT]
    I see what you guys are talking about now with bp_create_excerpt()!

    You can either request an additional parameter for unfiltered text in the “bp_blogs_record_activity_content” filter or in the “bp_create_excerpt” filter.
    Definitely a good idea for a patch!

    a crazy idea – the BP_Activity class on the save method has another set of filters.

    $this->content = apply_filters( 'bp_activity_content_before_save', $this->content, &$this );

    Using $this
    check for the activity type (new_blog_post),
    grab the secondary_item_id which is the post_id (item_id is the blog_id here)
    then lookup your custom excerpt in wp with the post_id and replace?

    Thank you both of you! Now I have a better start point!


    r-a-y
    Keymaster

    @r-a-y

    That would work as well!
    Though, you’d have to grab the excerpt either through a DB query or some WP functions (I suggest the DB query only if you’re using Multisite).

    Some free time returned.

    You can either request an additional parameter for unfiltered text in the “bp_blogs_record_activity_content” filter or in the “bp_create_excerpt” filter.

    So that now exists thanks to @r-a-y ( https://trac.buddypress.org/ticket/2481 )

    I’m assuming I need to tell bp_blogs_record_activity_content to use the excerpt, but would that just be using the code r-a-y already made here: http://pastebin.com/s9PajKjU or something else.


    r-a-y
    Keymaster

    @r-a-y

    @ipstenu – Take the code I posted and then you’ll also need to apply a filter so BP doesn’t create its own excerpt.

    This can be done with:
    http://pastebin.com/adaQBSTz

    Untested, give it a shot and report back.

    Okay, we’ll see how that goes (I have a scheduled post for 1am every day ;) )

    Oy. The fun!

    Brilliant!

    For posts without a crafted excerpt, it’s the same as always. For posts WITH one, it’s the excerpt! Now to trick it into pulling featured post images ;) ….


    cmscritic
    Participant

    @cmscritic

    Any luck getting it to pull in the first image of the blog post as well?


    Roger Coathup
    Participant

    @rogercoathup

    Some pointers, but not a solution:
    @ipstenu

    The featured image is referenced by _thumbnail_id . It’s not stored in the $post data structure, instead it’s held in the postmeta table.

    There are look up functions to get the featured image from the post_id of course, but not sure how efficient these would be… I guess you still have to have to switch to the correct blog (switch_to_blog()), before using the post_id in the 3.0 multisite world?

    Maybe I’m taking it off track here

    Yeah, switch to blog is why I’ve not gotten any further, alas :) I do wish this worked like FaceBook, somewhat, but unless I had it pulled in on bp_blogs_record_activity_content, maybe tell that ‘and get post_thumbnail_id’ but right now I’m happy with the excerpt!


    Roger Coathup
    Participant

    @rogercoathup

    @ipstenu:

    We came up with a solution to include the featured image (post_thumbnail) in the activity stream. The solution avoids the need to use switch_to_blog

    It isn’t simple, but it might help:

    We removed the action bp_blogs_record_post and replaced it with our own version that populates the content field with the post_thumbnail (you could also add the excerpt), i.e. `$activity_content = get_the_post_thumbnail( $post_id );`

    Unfortunately, bp_blogs_record_activity then takes the image and mangles it. To get around this we had to implement our own version of bp_blogs_record_activity, and call that instead from our blogs_record_post function.

    You can see the whole set of code here:

    http://pastebin.com/jKdQ2kLu

    Then in your activity loop, just use bp_activity_content_body() to display the thumbnail / excerpt, etc.

    IMHO – bp_blogs_record_activity() needs a rework in the core to give theme designers much more control.


    Bowe
    Participant

    @bowromir

    Thanks @rogercoathup for letting me know how to do this.. In the meantime I’ve taken another approach and added a featured posts slider (showing the post_thumbnail) and a excerpt above my activity stream. It’s a good solution for me, altough yours will come in handy for another project I’m working on :) thx!


    Michel Fortin
    Participant

    @fortinmichel

    Hmm. I’ve got the latest BP version, which has the https://trac.buddypress.org/ticket/2481 patch added, obviously. But I still don’t get my excerpts to show up — it still uses the fake excerpt created by BP rather than the post’s the_excerpt. Is there another bug?


    r-a-y
    Keymaster

    @r-a-y

    @fortinmichel – The patch allows you to override the auto-generated excerpt. You still need to actually write the code to override it.

    I already answered this question. Answer is available on the first page:
    https://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/replace-activity-stream-blog-excerpt-with-the_excerpt/#post-67290


    Michel Fortin
    Participant

    @fortinmichel

    Sorry, I was looking for more direction. I’m not a coder. I thought using the_excerpt would work or something right after applying the patch. Not sure about which kind of code I need to write, as your answer was confusing, which is why I posted it in this thread.


    Leo Plaw
    Participant

    @leoplaw

    @rogercoathup – the solution you provided on page one works for me.

    https://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/replace-activity-stream-blog-excerpt-with-the_excerpt?topic_page=1&num=15#post-69966

    However, is there anyway of having BuddyPress refreshing its activity streams? The above fix only works for updates or new posts AFTER it was implemented. All previous activities are showing their old content.


    cavamondo
    Participant

    @cavamondo

    Mystery why this hasnt been implemented as core feature in BP or developed as plugin, since using the post thumbnail is such an logic thing to do when displaying sitedwide blog posts in main site.


    stwc
    Participant

    @stwc

    Bookmark post.


    Roger Coathup
    Participant

    @rogercoathup

    @leoplaw – apologies for the late heads up – BP builds / stores all the activity records when the activity happens, not when you want to display them. So, all old activity will be as per the software you had running when the activity happened.

    If you want to process old activity and update them, you will need to write an activity loop, finding all relevant entries (e.g. user and / or activity type) and replacing the activity record appropriately. Perhaps something you’d write as a plugin, and trigger manually from wp-admin backend.

    I have the post thumbnail working for buddypress blog posts activity using the code from @rogercoathup but I’m struggling to figure out how to also add the content excerpt with it. Any help would be great, I imagine it’s quite simple I just don’t have a clue how to add it. Hopefully this will help other people who might be struggling with the same problem. I’m happy with the default auto excerpt from buddypress so long as I can limit the amount of characters. Thanks.


    Roger Coathup
    Participant

    @rogercoathup

    @tindell:

    adding the excerpt should be straightforward – around line 32 in my pastebin code (from page 1), after you’ve assigned the thumbnail to the activity_content – you’ll need to do something like:

    (for standard WP excerpt):

    $activity_content .= $post->post_excerpt;

    (for BP excerpt):

    $activity_content .= bp_create_excerpt ($post->post_content, 100) // to get the first 100 characters

    Note: I might have the syntax wrong on the BP (doing it off the top of my head) – so, you may need to check the function out, and experiment a little

    works great thanks.

Viewing 25 replies - 1 through 25 (of 41 total)
  • The topic ‘Replace Activity Stream blog excerpt with the_excerpt’ is closed to new replies.
Skip to toolbar