get_the_section_a_z_widget( array $args, array $instance )

Get the user-visible widget html


Description


Parameters

$args

(array) (Required) General widget configuration. Often shared between all widgets on the site.

$instance

(array) (Required) Configuration of this Widget. Unique to this invocation.


Return

(string) The complete A-Z Widget HTML ready for echoing to the page.


Source

File: widgets/class-a-z-listing-widget.php

function get_the_section_a_z_widget( $args, $instance ) {
	$classes = array( 'az-letters' );
	$instance = wp_parse_args( $instance, array(
		'title' => '',
		'post' => 0,
	) );

	if ( $instance['post'] ) {
		if ( $instance['post'] instanceof WP_Post ) {
			$target = $instance['post'];
		} elseif ( is_int( $instance['post'] ) && 0 < $instance['post'] ) {
			$target = get_post( (int) $instance['post'] );
		} else {
			return null;
		}
	} else {
		return null;
	}

	$title = $instance['title'];
	if ( empty( $title ) ) {
		$title = $target->post_title;
	}

	$post_type = ( isset( $instance['post_type'] ) ) ? $instance['post_type'] : 'page';
	$my_query = array(
		'post_type' => $post_type,
	);

	if ( isset( $instance['taxonomy'] ) && isset( $instance['terms'] ) ) {
		if ( ! empty( $instance['taxonomy'] ) && ! empty( $instance['terms'] ) ) {
			$my_query['tax_query'] = array(
				'taxonomy' => $instance['taxonomy'],
				'terms' => $instance['terms'],
			);
		}
	}

	if ( 'page' === $my_query['post_type'] ) {
		$parent = A_Z_Listing::find_post_parent( $target );
		if ( $parent->ID !== $target->ID ) {
			$my_query['child_of'] = $parent->ID;
		}
	}

	$a_z_query = new A_Z_Listing( $my_query );

	$ret = '';

	ob_start();
	?>

	<?php echo $args['before_widget']; // WPCS: XSS OK. ?>
	<?php echo $args['before_title'];  // WPCS: XSS OK. ?>
		<?php echo esc_html( $title ); ?>
	<?php echo $args['after_title']; // WPCS: XSS OK. ?>
	<div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
		<?php $a_z_query->the_letters( get_permalink( $target ), null ); ?>
		<div class="clear empty"></div>
	</div>
	<?php echo $args['after_widget']; // WPCS: XSS OK. ?>

	<?php
	$ret = ob_get_clean();
	return $ret;
}

Changelog

Changelog
VersionDescription
0.8.0Introduced.

More Information

You are currently logged out. To view tickets you must first login.

I have read and understood the Terms of Service



User Contributed Notes

Leave a Reply

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