当您使用分类法归档时(is_tax()
是true
) queried_object
以这种方式填充(来自我的网站的示例):
public \'queried_object\' =>
object(stdClass)[163]
public \'term_id\' => int 2
public \'name\' => string \'Puglia\' (length=6)
public \'slug\' => string \'puglia\' (length=6)
public \'term_group\' => int 0
public \'term_taxonomy_id\' => int 7
public \'taxonomy\' => string \'region\' (length=6)
public \'description\' => string \'Bari, Brindisi, Lecce, Taranto, Foggia\' (length=38)
public \'parent\' => int 0
public \'count\' => int 1
public \'filter\' => string \'raw\' (length=3)
public \'queried_object_id\' => int 2
因此,您可以直接获得名称和描述。您可以使用的代码是:
<?php
$current_term_name = $wp_query->queried_object->name;
$current_term_description = $wp_query->queried_object->description;
?>
<hgroup class="section-heading wrapper">
<h1><?php echo $current_term_name; ?></h1>
<h3><?php echo $current_term_description; ?></h3>
</hgroup>