How to get terms for taxonomy

时间:2015-08-06 作者:madu

如何获取分类法customcategorie的所有术语

我试图在分类法中保留代码。php

<?php

/*
Template Name:Taxoo



*/
get_header();



?>




<?php $term = get_term_by( \'slug\', get_query_var( \'term\' ), get_query_var( \'taxonomy\' ) ); ?>
<h2> 

<?php
$args = array(
\'type\' => \'post\',
\'child_of\' => 0,
\'parent\' => 0,
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hide_empty\' => 0,
\'hierarchical\' => 1,
\'taxonomy\' => \'customcategorie\'
);

foreach ( get_categories( $args ) as $taxonomy_cat ) {
  echo \'<li>\' . 
    wp_get_attachment_image( $taxonomy_cat->term_image, \'thumbnail\' ) . 
    $taxonomy_cat->name . 
    \'</li>\';
}



?>













<?php

get_footer();


?>

1 个回复
SO网友:Kishan

Try this code

<?php
//list terms in a given taxonomy
$taxonomy = \'industry\';
$tax_terms = get_terms($taxonomy);
?>
<ul>
<?php
foreach ($tax_terms as $tax_term) {
echo \'<li>\' . \'<a href="\' . esc_attr(get_term_link($tax_term, $taxonomy)) . \'" title="\' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . \'" \' . \'>\' . $tax_term->name.\'</a></li>\';
}
?>
结束

相关推荐