Html 如何在wordpress摘录中包含html标签?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6260928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 08:58:18  来源:igfitidea点击:

How to include html tags within a wordpress excerpt?

htmlwordpresstagshyperlink

提问by Daryl

Currently in a wordpress template, if you use the code the_excerpt()it will display the first 55 words of a post and strips all html from the post.

目前在 wordpress 模板中,如果您使用该代码the_excerpt(),它将显示帖子的前 55 个单词并从帖子中删除所有 html。

I need to include <a href...tags in the excerpt so that links are still visible.

我需要<a href...在摘录中包含标签,以便链接仍然可见。

Existing methods include:

现有方法包括:

  1. Hacking the wordpress core - definitely not an option.
  2. using a plugin - don't want to use, it's dependent on the developer keeping the plugin up to date
  3. writing code within functions.php to re-write the excerpt filter. - I'd prefer not to use this as it might have to be changed in future versions of WP
  1. 破解 wordpress 核心 - 绝对不是一种选择。
  2. 使用插件 - 不想使用,这取决于开发人员保持插件最新
  3. 在functions.php 中编写代码以重新编写摘录过滤器。- 我不想使用它,因为它可能需要在 WP 的未来版本中进行更改

Is there a filter hook or other known method to include html easily without hacks?

是否有过滤器钩子或其他已知方法可以轻松地包含 html 而无需黑客攻击?

All help is appreciated! Cheers.

感谢所有帮助!干杯。

采纳答案by stealthyninja

As I see it, you can only use method 2 and 3; both of them can be updated via WordPress' back-end with virtually no programming required which is ideal if you're going to be installing and using them on client sites.

在我看来,您只能使用方法 2 和 3;它们都可以通过 WordPress 的后端更新,几乎不需要编程,如果您要在客户端站点上安装和使用它们,这是理想的选择。

Here's a tutorial with working code for method 3 -- http://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/and here's a plugin to use method 2 -- http://wordpress.org/extend/plugins/advanced-excerpt/

这是方法 3 的工作代码教程——http://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/,这里是使用方法 2 的插件——http: //wordpress.org/extend/plugins /高级摘录/

回答by Box

I use the following statement sometimes to get the first 55 words of a post content.

我有时使用以下语句来获取帖子内容的前 55 个单词。

implode(' ', array_slice(explode(' ', get_the_content()), 0, 55));