2014-03-19 46 views
8
<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> 

这里echo substr($content,0,100);修剪the_content()无法正常工作时,从0裁剪内容100这个位于my_theme/functions/widgets/widget-portfolio-posts-thumbs.phpSUBSTR()不工作在WordPress的插件

+0

你检查$内容?它是否打印内容? –

回答

16

试试这个:

$content = get_the_content(); 
$content = strip_tags($content); 
echo substr($content, 0, 100); 
+0

它像一个魅力:)感谢 –

+0

不错,但它会更好。 if(strlen($ content)> 25){substructure($ content,0,50)。'...'; } else { echo $ content; } –

+0

但是如果你喜欢这个index.php页面,并且仍然想保持阅读状态,就像在使用'<?php the_content('Read more ...'); ?>'?因此,要加载一个起始于字符205的预告片,然后加入内置的字符数,然后再读取一个字符。 – rhand