2010-11-24 52 views
0

只是想知道是否有人可以幫助我解決以下問題。修剪字符顯示長度

在我網站的主頁上,我展示了來自Wordpress博客網站的3篇博文我已整合到網站中;所以我做了索引頁的動態,我已經添加了以下內容:

<div id="from-blog"> 
    <h2>Latest Blog Posts</h2> 
    <ul> 
      <?php while (have_posts()): the_post(); ?> 
     <li class="latest-entry-front"> 
       <span class="post-date"> 
       <span class="date-text"> 
        <span class="month"><?php the_time('M') ?></span><br/> 
        <span class="day"><?php the_time('d') ?></span> 
       </span> 
       </span> 
      <a href="<?php the_permalink(); ?>" title="Read full post"><?php the_title(); ?></a></li> 
       <?php endwhile; ?> 
     </ul> 
    </div> 

這裏的問題是,職位顯示其正在雜亂的,這是一個長的博客文章標題的全部博客標題;因此,有沒有辦法我可以修剪它只顯示最大數量的字符,然後在它或...

任何幫助非常感謝!

回答

0

編輯:

$title = the_title('', '', false);  
if(strlen($title) > $max_len) 
{ 
    echo substr($title, 0, $max_length) . "..."; 
} 
else 
{ 
    echo $title 
} 

應該爲你工作。

http://php.net/manual/en/function.substr.php

+0

嗨,你能告訴我我應該怎麼將其應用於我的代碼? – 2010-11-24 23:09:44

+0

肯定可以比爾。在wordpress中,你只需用the_title('','',false)替換$ title或者只是創建一個變量:$ title = the_title('','',false); http://codex.wordpress.org/Function_Reference/the_title對不起,由於某種原因,不能在這裏發佈代碼。 – 2010-11-24 23:14:08