修剪Wordpress Blogpost标题

时间:2017-04-28 04:59:52

标签: javascript jquery wordpress title posts

<h2 class="entry-title" itemprop="headline">
<a href="http://alzheimerscare.in/lorem-ipsum-is-simply-dummy-text-of-the-printing-and-typesetting-industry-lorem-ipsum-has-been-the-industrys/" title="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s" rel="bookmark">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s</a>
</h2>

我想将wordpress博客帖子标题修改为最少15个字符,页面中有很多帖子,我想用jquery或javascript修剪标题,每个帖子至少15个字符。谢谢。

1 个答案:

答案 0 :(得分:2)

这应该可以解决问题。它会在页面上找到每个标题,将其修剪为15个字符并添加&#34; ...&#34; - 除非你正在做某种&#34;显示/隐藏&#34;效果或其他东西,这可能会更好地完成在PHP;)

$(".entry-title a").each (function () {
  if ($(this).text().length > 15)
    $(this).text($(this).text().substring(0,15) + '...');
});