buddypress: how do i make the group description excerpt shorter?

I set up a theme in buddypress and i want to have a teaser section for my groups on there. It works fine but i have a problem to shorten the group description…

I’m using it like this:

Read More
<p><a href="<?php bp_group_permalink() ?>"><?php bp_group_name() ?></a></p>
<p><?php bp_group_description_excerpt() ?></p>

If there´s a very long group-description it crashes my layout. Is it possible (like in wordpress) to make the excerpt shorter (with a function or something)? Like “maximum of 20 letters”, or something like that?

Thanks.

Related posts

Leave a Reply

1 comment

  1. Custom API

    Write a normal API wrapper function for it and place it in your functions.php theme or offer it as (mu-)plugin.

    Trim Words

    /**
     * Trim Words Cb fn
     * @link Adjusted from http://snipplr.com/view.php?codeview&id=20397
     * 
     * @param string $excerpt Input string
     * @param int $count Word count
     * @param boolean/string $more Whether to show a "more" or not or a string
     * @return string $excerpt
     */
    function wpse50198_word_trim( $excerpt, $limit, $more = FALSE )
    {
        $output = explode( ' ', $excerpt );
        $count = count( $input );
    
        if ( $limit < $count )  )
            array_splice( $excerpt, $count, null, $output );
    
        if ( $more )
            $output .= $more;
    
        $output = implode( ' ', $output );
    
        return $output;
    }
    

    The Template Tag

    /**
     * 
     * @param bool $count Number of words to show - (default) 20
     * @param boolean/string $more Whether to show a "more" or not - (default) ...
     * @param bool $echo Print or return the excerpt - (default) TRUE
     * @return string $excerpt The reduced excerpt
     */
    function short_bp_group_descr_excerpt( $count = 20, $more = '&hellip', $echo = TRUE )
    {
        $excerpt = bp_get_group_description_excerpt();
        $length = str_word_count( $excerpt );
    
        if ( $count < $length )
            $excerpt = wpse50198_trim_words( $excerpt, $count, $more );
    
        if ( $echo )
            echo $excerpt;
    
        return $excerpt;
    }
    

    Usage

    Now, just call it like any template tag inside your template: short_bp_group_descr_excerpt();.