【问题标题】:Wordpress - Max. characters for latest post titlesWordPress - 最大。最新帖子标题的字符
【发布时间】:2015-11-14 19:50:08
【问题描述】:

在我的新网站 (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 个字符(包括空格)之后用 ... 删减最近帖子的标题,以便每个标题都固定在一行上。我如何在上面使用的代码中做到这一点?

提前致谢。

【问题讨论】:

标签: wordpress title


【解决方案1】:

您可以使用 css 轻松做到这一点,例如:

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

所以基本上你正在创建一个最大尺寸(最大高度/宽度)的 div,如果有溢出,隐藏它并显示...(省略号)

【讨论】:

  • 像魅力一样工作!谢谢。我从来不知道这个 css 函数存在。
猜你喜欢
  • 2018-01-22
  • 1970-01-01
  • 1970-01-01
  • 2014-12-22
  • 1970-01-01
  • 2013-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多