
只想截取第一段文字。WordPress 中没有相关的函数,但没关系,咱们自己定义一个。
下面的代码就是实现该功能的函数:
<?php/** * Get first paragraph from a WordPress post. Use inside the Loop. * * @return string */function get_first_paragraph(){ global $post; $str = wpautop( get_the_content() ); $str = substr( $str, 0, strpos( $str, '</p>' ) + 4 ); $str = strip_tags($str, '<a><strong><em>'); return '<p>' . $str . '</p>';}
结合该函数,修改下WordPress 的 the_content
函数就可以了。
人吐槽 | 人点赞 |
发表评论