WordPress如何在内容函数中将数据库中的原始数据转换为可读格式?
我注意到它应用了\\u内容过滤器,但是\\u内容过滤器做什么呢?
WordPress如何在内容函数中将数据库中的原始数据转换为可读格式?
我注意到它应用了\\u内容过滤器,但是\\u内容过滤器做什么呢?
默认过滤器在/wp includes/default filters中设置。php;
对于“the\\u content”,这来自第135行:
add_filter( \'the_content\', \'wptexturize\' );
add_filter( \'the_content\', \'convert_smilies\' );
add_filter( \'the_content\', \'convert_chars\' );
add_filter( \'the_content\', \'wpautop\' );
add_filter( \'the_content\', \'shortcode_unautop\' );
add_filter( \'the_content\', \'prepend_attachment\' );
要跟踪各个函数,可以尝试使用http://phpxref.ftwr.co.uk/wordpress/nav.html?_functions/index.html然后按照链接。。。wp-includes/default-filters.php
, 第102行):// Format WordPress
foreach ( array( \'the_content\', \'the_title\' ) as $filter )
add_filter( $filter, \'capital_P_dangit\', 11 );
所有过滤器都存储在全局$wp_filter
变量您可以检查该变量以查看哪些函数绑定到某个过滤器。
global $wp_filter;
print_r($wp_filter[\'the_content\']);
要准确了解输出的数组,请了解$wp_filter
变量的建立帮助很大。该行来自add_filter()
功能:$wp_filter[$tag][$priority][$idx] = array(\'function\' => $function_to_add, \'accepted_args\' => $accepted_args);
但是\\u内容过滤器做什么呢?
content\\u筛选器允许您在内容之前或之后返回自定义内容。
在自定义函数中使用\\u内容过滤器的两个非常基本的实际示例如下:
This example returns custom content before the content
add_filter( \'the_content\', \'return_before_content\' );
function return_before_content( $content ) {
if ( is_singular(\'post\')) {
$before_content = \'<p>Text Returned Before the_content</p>\';
$content = $before_content . $content;
}
return $content;
}
This example returns custom content after the content
add_filter( \'the_content\', \'return_after_content\' );
function return_after_content( $content ) {
if ( is_singular(\'post\')) {
$after_content = \'<p>Text Returned After the_content</p>\';
$content = $content . $after_content;
}
return $content;
}
我正在尝试向侧栏搜索框添加一些复选框选项,similar to this, 用户可以选择是否搜索All Words, Some Word, 或者Entire phrase.我确实在搜索后找到了这个-Wordpress Search Phrases. “句子”选项似乎很有效,但其他选项则不太好。下面的代码是我目前正在处理的,但如果能得到一些帮助使其正常工作,我将不胜感激。非常感谢S(我不想为此使用插件)。<form action=\"<?php bloginfo(\'home\'); ?>