Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( ! function_exists( 'themeplate_get_child_category' ) ) {
- function themeplate_get_child_category( $id ) {
- $taxonomy = 'category';
- global $post;
- // Get the term IDs assigned to post.
- $post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
- // Separator between links.
- $separator = ', ';
- if ( ! empty( $post_terms ) && ! is_wp_error( $post_terms ) ) {
- $term_ids = implode( ',' , $post_terms );
- $terms = wp_list_categories( array(
- 'title_li' => '',
- 'child_of' => $id,
- 'style' => 'none',
- 'echo' => false,
- 'taxonomy' => $taxonomy,
- 'include' => $term_ids
- ) );
- $terms = rtrim( trim( str_replace( '<br />', $separator, $terms ) ), $separator );
- // Display post categories.
- return '<div class="child-cat">' . $terms . '</div>';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement