2020-04-03 / 6870阅
注册了自定义分类法,我们添加分类以后,需要在前台调用分类法下面的分类。可以使用下面的函数:
$terms = get_terms( array( 'taxonomy' => 'post_tag', 'hide_empty' => false, ) );
其中,taxonomy是分类法的名称,hide_emypt设置为false,显示所有分类。
当然你可以可以写成下面的样式
$args = array ( 'taxonomy' => 'category', //empty string(''), false, 0 don't work, and return empty array 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, //can be 1, '1' too 'include' => 'all', //empty string(''), false, 0 don't work, and return empty array 'exclude' => 'all', //empty string(''), false, 0 don't work, and return empty array 'exclude_tree' => 'all', //empty string(''), false, 0 don't work, and return empty array 'number' => false, //can be 0, '0', '' too 'offset' => '', 'fields' => 'all', 'name' => '', 'slug' => '', 'hierarchical' => true, //can be 1, '1' too 'search' => '', 'name__like' => '', 'description__like' => '', 'pad_counts' => false, //can be 0, '0', '' too 'get' => '', 'child_of' => false, //can be 0, '0', '' too 'childless' => false, 'cache_domain' => 'core', 'update_term_meta_cache' => true, //can be 1, '1' too 'meta_query' => '', 'meta_key' => array(), 'meta_value'=> '', ); $terms= get_terms($args);
大部分参数我们是不常用的,但你还是需要根据视频了解下参数的用法
阅读文章或者观看视频过程中有任何问题,请下方留言或者联系我Q248758228