substr()无法修剪wordpress小部件中的the_content()

LIG*_*GHT 10 php wordpress

<div class="wpex-recent-posts-content clr">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a><p>
<?php
    $content = the_content();
    echo substr($content,0,100);
?>
</p>
</div>
Run Code Online (Sandbox Code Playgroud)

这里echo substr($content,0,100);不能裁剪从0到100的内容.这位于my_theme/functions/widgets/widget-portfolio-posts-thumbs.php

小智 19

试试这个:

$content = get_the_content();
$content = strip_tags($content);
echo substr($content, 0, 100);
Run Code Online (Sandbox Code Playgroud)