Wordpress分类法附件

时间:2016-01-12 11:18:52

标签: wordpress taxonomy

我创建了为自定义分类添加附件。它有效,但我不知道如何用附件打印分类法。

function add_stars_to_attachments() {
    register_taxonomy_for_object_type( 'star', 'attachment' );
}
add_action( 'init' , 'add_stars_to_attachments' );`

这是附件功能

我想打印像这样的分类术语:

  

[attachment] - [term_name]

有人知道吗?

2 个答案:

答案 0 :(得分:2)

WP有漂亮的手抄本See this guide

或者如果你想自己制作" custom" html使用this(伪代码)

您可以在$term对象

中查看与分类数据相关的所有内容
 $terms = get_terms( 'star' );
 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
     echo '<ul>';
     foreach ( $terms as $term ) {
       echo '<li>' . $term->name . '</li>';

     }
     echo '</ul>';
 }

答案 1 :(得分:0)

已解决:我添加了对分类法内容的附件,并使用$term->description

打印出来