2

我正在开发一个音乐博客,提供从 0.0 到 10 的评论分数。由于作者已经开发了在内容中输入分数的系统,我正在尝试找出一种更好地强调它们的方法。

例子:

"Score: 6.4" 

返回类似的东西

<div class="score">6.4</div>

有没有办法在数组中执行此操作,以将每个得分可能性放在 function.php 或 single.php 页面上。无论是更清洁的。

4

1 回答 1

1

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.

function expand_scores($content) {
 return preg_replace('/(score):\s*([\d.]+)/ims', '<div class="score">$1: $2</div>', $content);
}
add_filter('the_content', 'expand_scores');

Both the expand_scores and the add_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.

于 2010-03-26T21:14:54.610 回答