wordpress显示摘要
The source code highlighting was probably the first feature I was missing in WordPress. I briefly googled my options and decided it would be quicker to add the missing feature myself, since it looked pretty straightforward.
突出显示源代码可能是我在WordPress中缺少的第一个功能。 我简短地搜索了我的选项,并决定自己添加缺少的功能会更快,因为它看起来非常简单。
So what I did: 1. I added a hilite() function in functions-formatting.php <?php
所以我做了什么:1.我在functions-formatting.php <?php
添加了hilite()函数
function hilite($text)
函数 hilite ( $ text )
{
{
$text = str_replace('<? php', '<?php', $text);
$ text = str_replace ( '<?php' , '<?php' , $ text );
return preg_replace_callback(
返回preg_replace_callback (
"'<\?php.*?\?>'si",
“'<\?php。*?\?>'si” ,
create_function(
create_function (
'$matches',
'$ matches' ,
'return highlight_string($matches[0], true); '
'return Highlight_string($ matches [0],true); '
),
),
$text);
$ text );
}
}
?>
?>
The first line of the function is pretty curious, I agree. I needed it because I noticed that WP is adding a space between <
and ?
before saving to the database.
我同意,函数的第一行非常好奇。 我需要它,因为我注意到WP在<
和?
之间添加了一个空格?
保存到数据库之前。
2. I added call to the new function in default-filters.php
2.我在default-filters.php中添加了对新函数的调用
add_filter('the_content', 'hilite');
add_filter('the_content', 'hilite');
... just before this line
...就在这行之前
add_filter('the_content', 'wptexturize');
add_filter('the_content', 'wptexturize');
And it worked! Only that the highlighting itself for some reason is using the HTML font tag (God forbid!), but I believe that's server setup.
而且有效! 出于某种原因,仅突出显示自身是使用HTML字体标签(上帝禁止!),但我认为这是服务器设置。
Edit: I added the filter to one more place in default-filters.php, in order to highlight source code when listing excerpts, for example category listing on an archive listing. So default-filters.php looks more like:
add_filter('the_content', 'hilite'); add_filter('the_content', 'wptexturize'); add_filter('the_excerpt', 'hilite'); add_filter('the_excerpt', 'wptexturize');
编辑:我将过滤器添加到default-filters.php的另一个位置,以便在列出摘录时突出显示源代码,例如在归档列表中列出类别。 所以default-
add_filter('the_content', 'hilite'); add_filter('the_content', 'wptexturize'); add_filter('the_excerpt', 'hilite'); add_filter('the_excerpt', 'wptexturize');
看起来更像是:add_filter('the_content', 'hilite'); add_filter('the_content', 'wptexturize'); add_filter('the_excerpt', 'hilite'); add_filter('the_excerpt', 'wptexturize');
add_filter('the_content', 'hilite'); add_filter('the_content', 'wptexturize'); add_filter('the_excerpt', 'hilite'); add_filter('the_excerpt', 'wptexturize');
Tell your friends about this post on Facebook and Twitter
在Facebook和Twitter上告诉您的朋友有关此帖子的信息
wordpress显示摘要