Skip to content

Instantly share code, notes, and snippets.

@tkc49
Last active August 29, 2015 14:02
Show Gist options
  • Save tkc49/da2bea7cad0e98d2f3b8 to your computer and use it in GitHub Desktop.
Save tkc49/da2bea7cad0e98d2f3b8 to your computer and use it in GitHub Desktop.
タクソノミーを利用した際にターム一覧を表示する時のコード
<?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