Created
October 12, 2013 17:15
-
-
Save libo1106/6952496 to your computer and use it in GitHub Desktop.
WordPress中文摘要,按字数截取
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_post_excerpt($post, $excerpt_length=240){ | |
if(!$post) $post = get_post(); | |
$post_excerpt = $post->post_excerpt; | |
if($post_excerpt == ''){ | |
$post_content = $post->post_content; | |
$post_content = do_shortcode($post_content); | |
$post_content = wp_strip_all_tags( $post_content ); | |
$post_excerpt = mb_strimwidth($post_content,0,$excerpt_length,'…','utf-8'); | |
} | |
$post_excerpt = wp_strip_all_tags( $post_excerpt ); | |
$post_excerpt = trim( preg_replace( "/[\n\r\t ]+/", ' ', $post_excerpt ), ' ' ); | |
return $post_excerpt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment