【发布时间】:2011-01-14 01:34:14
【问题描述】:
WordPress 以这种格式发布帖子:
<h2>Some header</h>
<p>First paragraph of the post</p>
<p>Second paragraph of the post</p>
etc.
为了在第一段中获得我很酷的样式(这是其中一个看起来不错的东西),我需要挂钩到 get_posts 函数以使用 preg_replace 过滤其输出。
目标是让上面的代码看起来像:
<h2>Some header</h>
<p class="first">First paragraph of the post</p>
<p>Second paragraph of the post</p>
到目前为止我有这个但它甚至没有工作(错误是:“preg_replace()[function.preg-replace]:未知修饰符']'”)
$output=preg_replace('<p[^>]*>', '<p class="first">', $content);
我不能使用 CSS3 元选择器,因为我需要支持 IE6,并且我不能在父容器上应用 :first-line 元选择器(这是 IE6 支持的),因为它会命中H2 而不是第一个 P。
【问题讨论】:
-
嗯,我是否遗漏了什么,或者您可以更改页面模板以硬编码类属性而不是挂钩到
get_posts -
不能,因为P标签不是由模板创建的,它们是由wordpress吐出来的,wordpress通过autop钩子运行the_content,从而生成P。