【问题标题】:Trim Wordpress Blogpost Title修剪 Wordpress 博客文章标题
【发布时间】:2017-09-26 02:30:36
【问题描述】:
<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 个字符。谢谢。

【问题讨论】:

  • 通过 将 wordpress 博客文章标题修剪到最小 15 您的意思是将 wordpress 博客文章标题修剪到 最大 15
  • 是,最多 15 个 @Nico
  • ...你真的想用 jQuery 而不是 PHP 做到这一点?
  • 想要使用 Jquery 来做到这一点。 @mayersdesign

标签: javascript jquery wordpress title posts


【解决方案1】:

这应该可以解决问题。它找到页面上的每个标题,将其修剪为 15 个字符并添加“...” - 除非您正在执行某种“显示/隐藏”效果或其他东西,否则这可能会在 php 中更好地完成;)

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

【讨论】:

    猜你喜欢
    • 2015-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多