自定义API为其编写一个普通API包装函数,并将其放置在函数中。php主题或作为(mu-)插件提供。
修剪文字
/**
* 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;
}
模板标记
/**
*
* @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;
}
用法现在,只需像模板中的任何模板标记一样调用它:
short_bp_group_descr_excerpt();
.