如果日志没有填摘要,使用日志的第一段作为摘要是不错的选择,那么如何获取日志内容的第一段呢?可以使用下面的函数:
function get_first_p($post){ //如果是使用 Windows Live Writer 这些工具写日志,可能使用<p>和</p>进行分段 if(preg_match('/<p>(.*)<\/p>/iU',trim(strip_tags($post->post_content,"<p>")),$matches)){ return $matches[1]; } else { //如果直接在 WordPress 写日志,使用换行符(\n)来分段 $post_content = explode("\n",trim(strip_tags($post->post_content))); return $post_content ['0']; } }
发表评论