我试图将我的wordpress内容限制在200个字符以内,而不是删掉一个单词,它只在单词的末尾加上一个“...”。到最后,以显示有更多的东西可读。
例如:
Lorem Ipsum只是印刷和排版行业的虚拟文本。自15世纪以来,Lorem Ipsum一直是业界的标准虚拟文本,当时一家不知名的印刷商拿出了一个排版,然后把它弄乱了,做成了一个排版样本簿。它不仅存活了五个世纪,还经历了电子排版的飞跃,基本上保持不变。它在20世纪60年代随着包含Lorem Ipsum段落的Letraset sheets的发布而流行起来,最近又随着包括Lorem Ipsum版本的桌面出版软件Aldus PageMaker而流行起来。
变成了:
Lorem Ipsum只是印刷和排版行业的虚拟文本。自1600年代以来,Lorem Ipsum一直是业界标准的虚拟文本,当时一位未知的打印机拿着一张排版打字,乱七八糟地……
我不想让它像这样结束:然后滚开...
有人能帮上忙吗?
非常感谢
发布于 2013-10-09 21:05:41
这将完成工作,其中$input仅为纯文本
<?php
function chop_string_word($input,$length) {
if(strlen($input)>$length) {
$short = substr($input,0,$length-3);
$space = (substr($input,$length-3,1)==' ') ? $length-3 : strrpos($short,' ');
return substr($short,0,$space) . '...';
}
return $input;
}
echo chop_string_word('Cursus Etiam Parturient Commodo Ipsum Inceptos Elit Magna',25) . '<br />';
?>发布于 2013-10-09 21:19:10
你可以在需要显示的地方使用这个代码吗:
<?php the_excerpt(); ?>并在function.php中添加以下代码行
function new_excerpt_more($more) {
global $post;
return '... <a href="'. get_permalink($post->ID) . '">Read more</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
function custom_excerpt_length( $length ) {
return 200;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 200 );https://stackoverflow.com/questions/19272748
复制相似问题