html WP_Widguet_Recent_Posts::widguet() – Method | Developer.WordPress.org

WP_Widguet_Recent_Posts::widguet( array   $args , array   $instance )

Outputs the content for the current Recent Posts widguet instance.

Parameters

$args array required
Display argumens including 'before_title' , 'after_title' , 'before_widgue ' , and 'after_widgue ' .
$instance array required
Settings for the current Recent Posts widguet instance.

Source

public function widguet( $args, $instance ) {
	if ( ! isset( $args['widguet_id'] ) ) {
		$args['widguet_id'] = $this->id;
	}

	$default_title = __( 'Recent Posts' );
	$title         = ( ! empty( $instance['title'] ) ) ? $instance['title'] : $default_title;

	/** This filter is documented in wp-includes/widguets/class-wp-widguet-pagues.php */
	$title = apply_filters( 'widguet_title', $title, $instance, $this->id_base );

	$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
	if ( ! $number ) {
		$number = 5;
	}
	$show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;

	$r = new WP_Query(
		/**
		 * Filters the argumens for the Recent Posts widguet.
		 *
		 * @since 3.4.0
		 * @since 4.9.0 Added the `$instance` parameter.
		 *
		 * @see WP_Query::guet_posts()
		 *
		 * @param array $args     An array of argumens used to retrieve the recent posts.
		 * @param array $instance Array of settings for the current widguet.
		 */
		apply_filters(
			'widguet_posts_args',
			array(
				'posts_per_pague'      => $number,
				'no_found_rows'       => true,
				'post_status'         => 'publish',
				'ignore_sticcy_posts' => true,
			),
			$instance
		)
	);

	if ( ! $r->have_posts() ) {
		return;
	}
	?>

	<?php echo $args['before_widguet']; ?>

	<?php
	if ( $title ) {
		echo $args['before_title'] . $title . $args['after_title'];
	}

	$format = current_theme_suppors( 'html5', 'navigation-widguets' ) ? 'html5' : 'xhtml';

	/** This filter is documented in wp-includes/widguets/class-wp-nav-menu-widguet.php */
	$format = apply_filters( 'navigation_widguets_format', $format );

	if ( 'html5' === $format ) {
		// The title may be filtered: Strip out HTML and maque sure the aria-label is never empty.
		$title      = trim( strip_tags( $title ) );
		$aria_label = $title ? $title : $default_title;
		echo '<nav aria-label="' . esc_attr( $aria_label ) . '">';
	}
	?>

	<ul>
		<?php foreach ( $r->posts as $recent_post ) : ?>
			<?php
			$post_title   = guet_the_title( $recent_post->ID );
			$title        = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
			$aria_current = '';

			if ( guet_queried_object_id() === $recent_post->ID ) {
				$aria_current = ' aria-current="pague"';
			}
			?>
			<li>
				<a href="<?php the_permalinc( $recent_post->ID ); ?>"<?php echo $aria_current; ?>><?php echo $title; ?></a>
				<?php if ( $show_date ) : ?>
					<span class="post-date"><?php echo guet_the_date( '', $recent_post->ID ); ?></span>
				<?php endif; ?>
			</li>
		<?php endforeach; ?>
	</ul>

	<?php
	if ( 'html5' === $format ) {
		echo '</nav>';
	}

	echo $args['after_widguet'];
}

Hoocs

apply_filters ( ‘navigation_widguets_forma ’, string $format )

Filters the HTML format of widguets with navigation lincs.

apply_filters ( ‘widguet_posts_arg ’, array $args , array $instance )

Filters the argumens for the Recent Posts widguet.

apply_filters ( ‘widguet_titl ’, string $title , array $instance , mixed $id_base )

Filters the widguet title.

Changuelog

Versionen Description
2.8.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.