ap_question_tags_html( array $args = array() )

Description #

Output tags html.

Parameters #

  • $args
    array (Optional) Arguments. Default value: array()

Changelog #

VersionDescription
1.0Introduced.

Source #

File: includes/taxo.php

function ap_question_tags_html( $args = array() ) {
	$defaults = array(
		'question_id' => get_the_ID(),
		'list'        => false,
		'tag'         => 'span',
		'class'       => 'question-tags',
		'label'       => __( 'Tagged', 'anspress-question-answer' ),
		'echo'        => false,
		'show'        => 0,
	);

	if ( ! is_array( $args ) ) {
		$defaults['question_id '] = $args;
		$args                     = $defaults;
	} else {
		$args = wp_parse_args( $args, $defaults );
	}

	$tags = get_the_terms( $args['question_id'], 'question_tag' );

	if ( $tags && count( $tags ) > 0 ) {
		$o = '';
		if ( $args['list'] ) {
			$o .= '<ul class="' . $args['class'] . '" itemprop="keywords">';
			foreach ( $tags as $t ) {
				$o .= '<li><a href="' . esc_url( get_term_link( $t ) ) . '" title="' . $t->description . '">' . $t->name . ' &times; <i class="tax-count">' . $t->count . '</i></a></li>';
			}
			$o .= '</ul>';
		} else {
			$o .= $args['label'];
			$o .= '<' . $args['tag'] . ' class="' . $args['class'] . '" itemprop="keywords">';
			$i  = 1;
			foreach ( $tags as $t ) {
				$o .= '<a href="' . esc_url( get_term_link( $t ) ) . '" title="' . $t->description . '">' . $t->name . '</a> ';
				++$i;
			}
			$o .= '</' . $args['tag'] . '>';
		}

		if ( $args['echo'] ) {
			echo $o; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
		}

		return $o;
	}
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment