2014-03-19 48 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