我试图显示自定义分类法的术语列表,但遇到了一些问题。自定义税是针对名为project
.
我要做的是列出父项及其子项,例如:
绘画2013年,2012年,2011年,当您访问子术语的存档时,会出现相同的列表,显示父术语。
我已尝试使用wp_list_categories()
而且它有潜力,但我不知道如何为这些目的操纵它,这意味着当存档用于子术语时,不会显示父术语和所有其他子术语。
模板中的代码根本不起作用,它来自WP Codex示例。以下是模板代码:
global $wp_query;
$term = $wp_query->get_queried_object();
$title = $term->name;
$termID = $term->term_id;
$taxonomy_name = $term->taxonomy;
$termChildren = get_term_children( $termID, $taxonomy_name );
echo $title;
echo $termChildren;
echo \'<ul>\';
foreach ( $termChildren as $termChild ) {
$term2 = get_term_by( \'id\', $termChild, $taxonomy_name );
echo \'<li><a href="\' . get_term_link( $term2->name, $taxonomy_name ) . \'">\' . $term2->name . \'</a></li>\';
}
echo \'</ul>\';
这不会呈现列表,并会打断
foreach
陈述
为了更好地衡量,这里是海关税代码,以防我在那里做了蠢事:
add_action( \'init\', \'register_taxonomy_mediums\' );
function register_taxonomy_mediums() {
$labels = array(
\'name\' => _x( \'Mediums\', \'mediums\' ),
\'singular_name\' => _x( \'Medium\', \'mediums\' ),
\'search_items\' => _x( \'Search Mediums\', \'mediums\' ),
\'popular_items\' => _x( \'Popular Mediums\', \'mediums\' ),
\'all_items\' => _x( \'All Mediums\', \'mediums\' ),
\'parent_item\' => _x( \'Parent Medium\', \'mediums\' ),
\'parent_item_colon\' => _x( \'Parent Medium:\', \'mediums\' ),
\'edit_item\' => _x( \'Edit Medium\', \'mediums\' ),
\'update_item\' => _x( \'Update Medium\', \'mediums\' ),
\'add_new_item\' => _x( \'Add New Medium\', \'mediums\' ),
\'new_item_name\' => _x( \'New Medium\', \'mediums\' ),
\'separate_items_with_commas\' => _x( \'Separate mediums with commas\', \'mediums\' ),
\'add_or_remove_items\' => _x( \'Add or remove mediums\', \'mediums\' ),
\'choose_from_most_used\' => _x( \'Choose from the most used mediums\', \'mediums\' ),
\'menu_name\' => _x( \'Mediums\', \'mediums\' ),
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'show_in_nav_menus\' => true,
\'show_ui\' => true,
\'show_tagcloud\' => true,
\'show_admin_column\' => true,
\'hierarchical\' => true,
\'has_archive\' => true,
\'rewrite\' => true,
\'query_var\' => true
);
register_taxonomy( \'mediums\', array(\'project\'), $args );
}
任何帮助都会很好。谢谢