Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Helper class to insert taxonomy terms after BuddyBlog Pro excerpts.
- */
- class BBL_Custom_Tax_Lister {
- /**
- * Taxonomy name.
- *
- * @var string
- */
- private string $taxonomy;
- /**
- * Label to use before the terms list.
- *
- * @var string
- */
- private string $label = '';
- /**
- * Constructor.
- *
- * @param string $taxonomy Taxonomy name.
- * @param string $label Label to use before the terms list.
- */
- public function __construct( string $taxonomy, string $label = '' ) {
- $this->taxonomy = trim( $taxonomy );
- $this->label = trim( $label );
- }
- public function setup() {
- add_action( 'bblpro_post_meta_actions', array( $this, 'list_terms' ) );
- }
- public function list_terms( $post_id ) {
- // we only sho it on posts loop, not on single page.
- if ( ! $this->taxonomy || is_single( $post_id ) ) {
- return;
- }
- $terms = wp_get_post_terms( $post_id, $this->taxonomy );
- if ( empty( $terms ) || is_wp_error( $terms ) ) {
- return;
- }
- $term_links = array();
- foreach ( $terms as $term ) {
- $term_links[] = sprintf( '<a href="%s">%s</a>', get_term_link( $term ), $term->name );
- }
- $output = sprintf( '<div class="bbl-custom-terms-list bbl-custom-%s-terms-list">', esc_attr( $this->taxonomy ) );
- if ( $this->label ) {
- $output .= sprintf( '<span class="bbl-custom-taxonomy-label">%s</span>', esc_html( $this->label ) );
- }
- $output .= join( ', ', $term_links );
- $output .= '</div>';
- echo $output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement