您的位置:首页 > 其它

WordPress主题开发:截取标题或内容

2017-02-02 22:08 260 查看
截取可以用wp_trim_words()

用法:

<?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ?>


参数说明:$text---截取内容,$num_words ---限定字数,$more ---截取后加在尾部的字符

截取文章内容:

<?php
$content = get_the_content();
$trimmed_content = wp_trim_words( $content, 40, '<a href="'. get_permalink() .'"> ...Read More</a>' );
echo $trimmed_content;
?>


截取文章标题:

<?php
$title = get_the_title();
$trimmed_title = wp_trim_words( $title, 20, '...' );
echo $trimmed_title;
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: