【发布时间】:2011-03-30 03:58:58
【问题描述】:
这是我第一次使用过滤器,如果这看起来很简单,请原谅我。我已经安静地进行了一些谷歌搜索,但找不到与我的问题相关的任何内容,从我所能找到的一切来看,这应该可以正常工作。据我了解,手动添加的过滤器与 wordpress 自动运行的任何其他过滤器同时运行,即:创建我自己的过滤器将与 wordpress 的默认 wpautop 和 wptexturize 过滤器一起运行。
但由于某种原因,我添加的过滤器运行良好,除了现在 wpautop 和 wptexturize 无法在 the_content 上运行。从函数中删除我的自定义过滤器后,默认过滤器再次触发。没有安装其他修改输出的插件。如果您发现我的陈述有问题,我们将非常感谢您提供任何帮助以及任何关于更好方法的一般性建议。
function tumblr_chat_post($content) {
global $post;
$content = $post->post_content;
if ($post->post_type == 'post') {
$postcats = wp_get_object_terms($post->ID, 'category');
foreach ($postcats as $mycat) {
if ($mycat->name == "chats") {
$chatoutput = "<dl class=\"transcript\">\n";
$split = preg_split("/(\r?\n)+|(<br\s*\/?>\s*)+/", $content);
foreach($split as $haystack) {
if (strpos($haystack, ":")) {
$string = explode(":", trim($haystack), 2);
//list($who, $what) = explode(":", $haystack, 2);
$who = trim($string[0]);
$what = trim($string[1]);
$row_class = empty($row_class)? " class=\"alt\"" : "";
$chatoutput = $chatoutput . "<dt$row_class><b>$who:</b></dt> <dd><i>$what</i></dd>\n";
}
else {
// the string didn't contain a needle so we will keep it and output it later
$no_chatoutput = $no_chatoutput . $haystack . "\n";
}
}
// print our new formated chat post and push unformatted content to the end of the post.
$content = $chatoutput . "</dl>\n" . $no_chatoutput;
return $content;
}
else {
// I don't exist in the defined category, so no processing is needed
return $content;
}
}
}
else {
// I'm not a regular post, so no processing is needed.
return $content;
}
}
add_filter( "the_content", "tumblr_chat_post", 20);
【问题讨论】: