2024年10月18日 建站教程
wordpress如何把文章的第一段显示为摘要,并且不显示文章中的标签,可以在需要显示摘要的地方,直接使用以下函数。
function get_first_p($post) { //利用正则表达式匹配p标签提取第一段内容 if(preg_match('/(.*)<\/p>/iU',trim(strip_tags($post->post_content,"")),$matches)){ return$matches[1]; }else{ //有时文章可能是通过软回车分段的\n为分段标记 $post_content=explode("\n",trim(strip_tags($post->post_content))); return$post_content['0']; } }
本文链接:http://so.lmcjl.com/news/15662/