Created
October 27, 2016 11:13
-
-
Save Restoration/b8a906759bceeca21a3cafd2301f4f08 to your computer and use it in GitHub Desktop.
get_termsでカスタムタクソノミー一覧表示
This file contains hidden or 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 | |
| $taxonomy = 'product'; | |
| $args = array( | |
| 'pad_counts' => true, | |
| 'hide_empty' => false | |
| ); | |
| $terms = get_terms( $taxonomy , $args ); | |
| if ( count( $terms ) != 0 ) { | |
| echo '<ul>'; | |
| foreach ( $terms as $term ) { | |
| $term = sanitize_term( $term, $taxonomy ); | |
| $term_link = get_term_link( $term, $taxonomy ); | |
| if ( is_wp_error( $term_link ) ) { | |
| continue; | |
| } | |
| if( $term->parent != 0 ) { | |
| echo '<li class="children">'; | |
| } else { | |
| echo '<li>'; | |
| } | |
| echo '<a href="' . esc_url( $term_link ) . '">' . $term->name . '</a>(' . $term->count . ')'; | |
| echo '</li>'; | |
| } | |
| echo '</ul>'; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment