在里面wp-includes/post-template.php
您将找到应用过滤器的位置:
/**
* Display the post content.
*
* @since 0.71
*
* @param string $more_link_text Optional. Content for when there is more text.
* @param string $stripteaser Optional. Teaser content before the more text.
*/
function the_content($more_link_text = null, $stripteaser = 0) {
$content = get_the_content($more_link_text, $stripteaser);
$content = apply_filters(\'the_content\', $content);
$content = str_replace(\']]>\', \']]>\', $content);
echo $content;
}
唯一的参数是内容文本。
但您始终可以使用全局变量$post来获取有关当前使用的post的更多信息。在主题函数中尝试以下代码段。php:
/*
* Priority 100 to let other filters do their work first.
*/
add_filter( \'the_content\', \'debug_post_info\', 100 );
/**
* Print information about the current post.
*
* @param string $content
* @return string
*/
function debug_post_info( $content )
{
return $content . \'<hr><pre>\' . var_export( $GLOBALS[\'post\'], TRUE ) . \'</pre>\';
}
在子页面上,您可以获得一些不错的数据:
stdClass::__set_state(array(
\'ID\' => 2168,
\'post_author\' => \'2\',
\'post_date\' => \'2007-09-04 09:52:18\',
\'post_date_gmt\' => \'2007-09-03 23:52:18\',
\'post_content\' => \'This page has a parent.\',
\'post_title\' => \'Child page 2\',
\'post_excerpt\' => \'\',
\'post_status\' => \'publish\',
\'comment_status\' => \'open\',
\'ping_status\' => \'open\',
\'post_password\' => \'\',
\'post_name\' => \'child-page-2\',
\'to_ping\' => \'\',
\'pinged\' => \'\',
\'post_modified\' => \'2007-09-04 09:52:18\',
\'post_modified_gmt\' => \'2007-09-03 23:52:18\',
\'post_content_filtered\' => \'\',
\'post_parent\' => 2167,
\'guid\' => \'http://wpthemetestdata.wordpress.com/parent-page/child-page-1/child-page-2/\',
\'menu_order\' => 0,
\'post_type\' => \'page\',
\'post_mime_type\' => \'\',
\'comment_count\' => \'0\',
\'ancestors\' =>
array (
0 => 2167,
1 => 2166,
),
\'filter\' => \'raw\',
))
\'post_parent\' => 2167
是父帖子的ID。在没有父级的页面上,参数设置为
0
.