WordPress获取多个分类法对象函数:get_terms
WordPress函数get_terms根据WP_Term_Query参数获取分类法对象,返回多个分类数据。 …
WordPress函数get_terms根据WP_Term_Query参数获取分类法对象,返回多个分类数据。
get_terms( array|string $args = array(), array|string $deprecated = '' )
函数参数
$args
数组,参数可用值参考get_categories()函数的$args参数说明
函数返回值
Array
(
    [0] => WP_Term Object
        (
            [term_id] => 2
            [name] => 开发
            [slug] => develop
            [term_group] => 0
            [term_taxonomy_id] => 2
            [taxonomy] => category
            [description] => 
            [parent] => 1
            [count] => 100
            [filter] => raw
        )
    [1] => WP_Term Object
        (
            [term_id] => 3
            [name] => 教程
            [slug] => courses
            [term_group] => 0
            [term_taxonomy_id] => 3
            [taxonomy] => category
            [description] => 
            [parent] => 1
            [count] => 220
            [filter] => raw
        )
    ......
)函数使用示例
$categories = get_terms( array( 
    'taxonomy' => 'category',
    'parent'   => 1
) );
foreach($categories as $category) {
	echo '<li><a href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></li>';
}扩展阅读
get_terms()函数位于:wp-includes/taxonomy.php
相关函数:
- get_term()
 - get_category()
 - get_categories()
 - get_term_by()
 - get_term_children()
 - taxonomy_exists()
 
类别:WordPress函数讲解、 
		本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!