Last active
August 29, 2015 14:02
-
-
Save tkc49/da2bea7cad0e98d2f3b8 to your computer and use it in GitHub Desktop.
タクソノミーを利用した際にターム一覧を表示する時のコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $target_taxonomy = "taxonomy-name"; // タクソノミー名を変数に設定する ?> | |
<?php $terms = get_terms($target_taxonomy,array('hide_empty' => false, )); // 空のタームも取得できるようにする ?> | |
<?php if ( !empty( $terms ) && !is_wp_error( $terms ) ): // 空かつエラーではないか ?> | |
<ul> | |
<?php foreach ( $terms as $term ): ?> | |
<li><a href="<?php echo get_term_link($term,$target_taxonomy); ?>"><?php echo $term->name; ?></a></li> | |
<?php endforeach; ?> | |
</ul> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference:
http://codex.wordpress.org/Function_Reference/get_terms
http://codex.wordpress.org/Function_Reference/get_term_link