在前后打印带有可选文本的类别。
原型
the_category_head( string $before = '', string $after = '' )
参数
$before
(string)
(Optional)
要在类别之前显示的文本。
$after
(string)
(Optional)
类别后显示的文本。
源文件
路径:wp-includes/deprecated.php
<?php
...
function the_category_head( $before = '', $after = '' ) {
global $currentcat, $previouscat;
_deprecated_function( __FUNCTION__, '0.71', 'get_the_category_by_ID()' );
// Grab the first cat in the list.
$categories = get_the_category();
$currentcat = $categories[0]->category_id;
if ( $currentcat != $previouscat ) {
echo $before;
echo get_the_category_by_ID($currentcat);
echo $after;
$previouscat = $currentcat;
}
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/the_category_head/