wp 任意摘要长度问题

content 和 sidebar理应长度不一致 

哥找了半天 找到一个

随机自定义摘要长度  博文

http://www.cnxsz.com/jzcx/blog/12697.html

 

http://wp-snippets.com/dynamic-custom-length-excpert/

 在functions中添加

/*控制摘要长度*/
// Variable & intelligent excerpt length.
function print_excerpt($length) { // Max excerpt length. Length is set in characters
global $post;
$text = $post->post_excerpt;
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
}
$text = strip_shortcodes($text); // optional, recommended
$text = strip_tags($text); // use ' $text = strip_tags($text,'<p><a>'); ' if you want to keep some tags

$text = mb_substr($text,0,$length);
$excerpt = reverse_strrchr($text, '.', 1);
if( $excerpt ) {
echo apply_filters('the_excerpt',$excerpt);
} else {
echo apply_filters('the_excerpt',$text);
}
}

 

<?php print_excerpt(50); ?>




posted @ 2012-09-20 19:36  hust_zk  阅读(208)  评论(0编辑  收藏  举报