Để lấy tất cả danh sách chuyên mục theo taxonomy trong wordpress ta sử dụng hàm sau .
[php]
wp_list_categories( string|array $args = ” )
[/php]
Cách viết như sau :
[php]
echo ‘<ul>’;
wp_list_categories( array(
‘taxonomy’ => ‘ten_taxonomy_cua_ban’,
‘title_li’ => 0,
‘hide_empty’ => 0,
‘order’ => ‘ASC’,
‘orderby’ => ‘id’,
) );
echo ‘</ul>’;
[/php]
và đây là kết quả hiển thị
Tham khảo thêm các giá trị mặc định của hàm wp_list_categories , các bạn xem và thay đổi giá trị để phú hợp nhất với nhu cầu của các bạn:
[php]
$defaults = array(
‘child_of’ => 0,
‘current_category’ => 0,
‘depth’ => 0,
‘echo’ => 1,
‘exclude’ => ”,
‘exclude_tree’ => ”,
‘feed’ => ”,
‘feed_image’ => ”,
‘feed_type’ => ”,
‘hide_empty’ => 1,
‘hide_title_if_empty’ => false,
‘hierarchical’ => true,
‘order’ => ‘ASC’,
‘orderby’ => ‘name’,
‘separator’ => ‘<br />’,
‘show_count’ => 0,
‘show_option_all’ => ”,
‘show_option_none’ => __( ‘No categories’ ),
‘style’ => ‘list’,
‘taxonomy’ => ‘category’,
‘title_li’ => __( ‘Categories’ ),
‘use_desc_for_title’ => 1,
);
[/php]
chú thích : xem thêm tại wp