通过下面的内容,您可以从event\\u category taxonomyNote中获取术语,但您总是获取相同的术语。
$terms = get_terms(
\'event_category\',
array(
\'orderby\' => \'count\',
\'hide_empty\' => true
)
);
如果只想从当前页面中获取子项,则应获取当前术语,并将术语列表设置为仅获取当前术语的子项:
$current_term = $wp_query->queried_object;
$terms = get_terms(
\'event_category\',
array(
\'orderby\' => \'count\',
\'hide_empty\' => true,
\'parent\' => $current_term->parent
)
);
你在这里骑自行车穿过它们。。。
foreach( $terms as $term ) {
// Check and see if the term is a top-level parent. If so, don\'t display it.
$parent = $term->parent;
if ( $parent!=\'0\' ) {
// Define the query
您试图对此查询执行什么操作?您正在创建它,但却什么都不做。
$args = array(
\'post_type\' => \'events\',
\'event_category\' => $term->slug
);
$query = new WP_Query( $args );
这只是写出一个链接:
echo\'<a href="\'.home_url().\'/big-events/\'.$term->slug.\'"><span class="cat-name">\' . $term->name . \'</a>\';
最好采取以下措施:
echo \'<a href="\' . get_permalink($term) . \'"><span class="cat-name">\' . $term->name . \'</span></a>\';
}
}
?>
重写一点:
<?php
$current_term = $wp_query->queried_object;
$children = get_terms(
\'event_category\',
array(
\'orderby\' => \'count\',
\'hide_empty\' => true,
\'parent\' => $current_term->parent
)
);
if ( !is_wp_error( $children ) && is_array( $children ) && 0 < count( $children ) ) {
foreach ( $children as $child_term ) {
$child_link = get_permalink( $child_term );
echo <<<HTML
<a href="{$child_link}"><span class="cat-name">{$child_term->name}</span></a>
HTML;
}
} else {
# No child terms were found
}
?>