替换 WordPress 内容中的字符串数组
我正在开发一个音乐博客,提供从 0.0 到 10 的评论分数。由于作者已经开发了在内容中输入分数的系统,因此我正在尝试找到一种方法来更好地强调它们。
示例:
"Score: 6.4"
返回类似
<div class="score">6.4</div>
Is there way to do this in a array 将每个分数可能性放在 function.php 或 single.php 页面上。随便什么都比较干净。
I'm working on a music blog that provides review scores ranging from 0.0 - 10. Since the authors already developed their system of typing in the score in the content, I'm trying figure out a way to emphasis them better.
Example:
"Score: 6.4"
returns something like
<div class="score">6.4</div>
Is there way to do this in an array to put every score possibility down within function.php or on the single.php page. Whatever is cleaner.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以对内容进行正则表达式搜索/替换。然后,您可以通过创建插件并使用 wp add_filter 函数将其连接到 Wordpress。
expand_scores
和add_filter
调用都会进入您的插件文件。 the_content 挂钩将 Expand_scores 函数应用于打印前从数据库检索的所有发布数据。You can do a regular expression search/replace for the content. Then you can hook it into Wordpress by creating a plugin and using the wp add_filter function.
Both the
expand_scores
and theadd_filter
call go into your plugin file. The the_content hook applies the expand_scores function to all post data retrieved from the database before printing.