From fb85ef43c6ab592d9f4049a19cbf3c49d78c292b Mon Sep 17 00:00:00 2001 From: bplv112 Date: Thu, 22 Sep 2022 16:28:00 -0500 Subject: [PATCH] added:: Taxonomy printing helper functions. --- inc/template-tags/print-post-taxonomies.php | 63 +++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 inc/template-tags/print-post-taxonomies.php diff --git a/inc/template-tags/print-post-taxonomies.php b/inc/template-tags/print-post-taxonomies.php new file mode 100644 index 000000000..126a57707 --- /dev/null +++ b/inc/template-tags/print-post-taxonomies.php @@ -0,0 +1,63 @@ + '', + 'post_id' => get_the_ID(), + 'linked' => true, + 'in_list' => true, + ]; + + // Parse args. + $args = wp_parse_args( $args, $defaults ); + + // Bail early if we have no post id or taxonomy name. + if ( empty( $args['post_id'] ) || empty( $args['tax_name'] ) ) : + return; + endif; + + // Get the terms. + $wd_s_terms = get_the_terms( $args['post_id'], $args['tax_name'] ); + + // Set up the display. + $wd_s_tagname = $args['in_list'] ? 'ul' : 'span'; + ?> + + < class="post-taxonomies"> + ' : '' ); + if ( $args['linked'] ) : + print_element( + 'anchor', + [ + 'text' => $wd_s_term->name, + 'href' => get_term_link( $wd_s_term->term_id, $args['tax_name'] ), + ] + ); + else : + echo esc_html( $wd_s_term->name ); + endif; + echo $args['in_list'] ? '' : ''; + endforeach; + ?> + > + +