我在WP的一个页面中有此代码,用于显示新的分类法
<?php
$terms = get_terms(array(
\'hide_empty\' => \'false\',
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'taxonomy\' => \'mylist\'
));
foreach ($terms as $category) {
echo \'<div class="col-ms-4">\';
echo \'<div class="category-list">\';
echo \'<a href="\' . get_category_link( $category->term_id ) . \' "><div class="image_wrapper is-image list-image">\'. do_shortcode(sprintf(\'[wp_custom_image_category term_id="%s"]\',$category->term_id)). \'</div></a>\' ;
echo \'<div class="image-category"><h2 class="title-category"><a href=" \' . get_category_link( $category->term_id ) . \' "> \'.$category->name.\' </a></h2></div>\';
echo \'<div class="category-count"><a>\' . $category->count . \'</a></div>\';
echo \'</div>\';
echo \'</div>\';
} ?>
但这是行不通的。你有在WordPress上显示新分类法的想法吗?使用此代码
最合适的回答,由SO网友:Alexander Holsgrove 整理而成
功能,如get_categories
是post类别分类法所独有的。“类别”是一个分类术语。如果注册自己的分类法,则需要使用get_terms 其参数与get_categories 作用
$terms = get_terms(array(
\'hide_empty\' => false,
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'taxonomy\' => \'your-taxonomy\'
));