dplase3140 2010-11-24 22:48
浏览 16

修剪字符显示长度

Just wondering if someone can assist me with the following issue.

On the HOME page of my site I'm displaying 3 Blog posts from the Wordpress Blog site I have intergrated into the website; therefore I have made the index page dynamic and I've added the following:

<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>

The issue here is that the posts are displaying the full blog title which is looking messy of it was a long Blog post title; therefore is there a way I can trim it to only display a maximum amount of characters and then [...] after it or ...

Any help much appreciated!

  • 写回答

2条回答 默认 最新

  • duanmingting9544 2010-11-24 22:55
    关注

    Edit:

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

    should work for you.

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

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b