Skip to:
Content
Pages
Categories
Search
Top
Bottom

Limiting excerpts in the site-wide activity widget

  • Avatar of Korhan Ekinci
    Korhan Ekinci
    Participant

    @korhanekinci

    my question is, how do i limit the number of words (excerpt)(currently 55) of blog posts that appear on the site wide activity widget???

    I did edit the formatting.php file but that did not work. Where is it exactly???

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Avatar of Greg
    Greg
    Participant

    @gregeland

    I am looking for how to do this also. If there are consecutive blog posts in the feed it gets way too long. It seems like you could just add a filter to trim the excerpt, but I can’t find where to add this. Could anyone point us in the right direction?

    Avatar of andrepan
    andrepan
    Participant

    @andrepan

    mmm, seems I also have this requirement

    Avatar of dpolant
    dpolant
    Participant

    @dpolant

    Here is one way to do it I believe. Put this filter and function inside a plugin or your custom.php.

    add_filter('bp_blogs_activity_new_post', 'my_process', 2, 3 );

    function my_process($activity_content, $post, $post_permalink){

    $activity_content = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
    $activity_content .= "<blockquote>" . bp_create_excerpt( $post->post_content, 25 ) . "</blockquote>";

    return $activity_content;
    }

    I think this is the most efficient way of doing this. Basically, this code snippet overrides the content of the activity notification for a new blog entry. It is unfortunate that you have to write all the other crap again, but as you can see the thing you want to change (bp_create_excerpt) doesn’t have its own filter.

    The good news is, unlike some approaches to this problem, this solution doesn’t require that you alter the core.

    Try it and see if it works. Sorry ’bout the layout overflow :(

    Avatar of bpisimone
    bpisimone
    Participant

    @bpisimone

    That is a great method @dpolant! I however wanted to insert this snippet here before

    <blockquote>

    but it’s not accepting it. Mainly the url value is not accepted I think, how is that done correctly?

    $activity_content .= "<img height="20" width="20" class="bla" alt="bla" src="http://wordpress.mu/(...)/bla.png"/><blockquote>"

    Thanks!

    Avatar of dpolant
    dpolant
    Participant

    @dpolant

    Watch your escape quotes. Each time you write a double quote, it ends the previous quoted segment. If you start a quoted string with double quotes, use single quotes to indicate quotation marks inside. It works as vice versa as well.

    If you already knew that and simply wrote it all with double quotes for your demonstration, I would advise that you double check your path to your image.

    A word of advice about paths: it is usually a good idea not to hard-code the whole path. It will work on your site if you get it right, but if you ever move things it will break. Instead, use defined constants to represent these path components. WP_PLUGIN_URL points to your plugins directory, and get_option(‘siteurl’) will assume the value of your root domain, with http://. Here is a link that has some more of these useful constants.

    Hope this helps.

    Avatar of John James Jacoby
    John James Jacoby
    Keymaster

    @johnjamesjacoby

    Add a ticket in the trac to add a filter to bp_create_excerpt and we can make this easier in a future version.

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

You must be logged in to reply to this topic.