2011-12-26 169 views
1

我正在重新設計我的網站,並發現自己需要在側邊欄上顯示帖子摘錄。 the_excerpt()似乎是正確的使用,但我也在我的主博客頁面上使用摘錄。 55個字的限制在我的主頁上看起來不錯,但不是我的側邊欄。我需要一種方法來限制僅在我的側邊欄中在the_excerpt中返回的單詞。在側欄顯示帖子摘錄?

<div id="sidebar"> 
    <a href="<?php the_permalink(); ?>" title="Permalink to <?php the_title(); ?>"> 
     <?php the_title() ?> 
    </a> 
    <?php the_excerpt(); ?> 
</div> 

我想在側邊欄,摘錄長度被限制到類似20個字

+0

試試這個 - > HTTP:/ /wordpress.org/extend/plugins/content-and-excerpt-word-limit/ – Rikesh 2011-12-26 05:11:02

回答

0

您可以使用SUBSTR()

<div id="sidebar"> 
    <a href="<?php the_permalink(); ?>" title="Permalink to <?php the_title(); ?>"> 
     <?php the_title() ?> 
    </a> 
    <?php $mycontent=get_the_excerpt(); 
     echo substr($mycontent,0,20); 
    ?> 
</div> 
相關問題