Wordpress-最新文章标题的最大字符数



在我的新网站主页上(http://tinyurl.com/q53ccn8)我在我的新闻滑块下显示最近的帖子(标题=Nieuws)。

我用以下代码来做这件事:

<?php $args = array( 'numberposts' => '5', 'offset' => 6,); $recent_posts = wp_get_recent_posts( $args ); foreach( $recent_posts as $recent ){ echo '<li class="list-group-item"><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"].'</a> </li> ';}?> 

现在,我想删掉最近帖子的标题。。。在40个字符(包括空格)之后,所以每个标题都固定在一行。我如何在上面使用的代码中做到这一点?

提前谢谢。

使用css可以很容易地做到这一点,例如:

.textDiv{
   line-height: 10px;
   height: 12px;
   width: 100%;
   max-width: 100%;
   max-height: 12px;
   overflow: hidden;
   text-overflow: ellipsis;
}

因此,基本上,您正在创建一个具有最大维度(最大高度/宽度)的div,如果有溢出,请将其隐藏并显示。。。(省略号)

最新更新