我有以下分类法:
Location:
Province
--City
----Suburb
Province
--City
----Suburb
如何在存档页上呼应“郊区”(二级)的名称?
例如:
Location:
Western Cape
--Cape Town
----Tokai
我怎么能只回应“东海”?
Edit:
这是我的档案。php(通过主页上的两个选择下拉菜单访问):
echo esc_attr(get_search_query());
//FIRST QUERY
$args = array(
\'order\' => \'DESC\',
\'orderby\' => \'modified\',
\'posts_per_page\' => -1,
);
//SECOND QUERY
$args2 = array (
...different args for second query...
);
$new_args = http_build_query($args);
$query = new WP_Query($query_string.\'&\'.$new_args);
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
the_title();
the_post_thumbnail();
<need the taxonomy name to go here (3rd child)>
最合适的回答,由SO网友:Alex Pogiba 整理而成
您可以使用该代码检索分类列表中的最后一个分类术语:
在您的functions.php 文件创建自定义函数:
function my_custom_function() {
global $post;
$terms = get_the_terms( $post->ID, \'location\' );
if (!empty($terms)) {
foreach($terms as $term) {
if (!get_term_children($term->term_id, \'location\')) {
echo $term->name;
}
}
}
}
何时,在您的
archive.php 您应该调用新创建的自定义函数:
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
the_title();
the_post_thumbnail();
<need the taxonomy name to go here (3rd child)>
<?php my_custom_function(); ?>
结果: