2010-11-24 139 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