wppaste
WordPress

WP_Widget_Archives::widget( array $args, array $instance )

Since
2.8.0
Source
wp-includes/widgets/class-wp-widget-archives.php:43
Outputs the content for the current Archives widget instance.

Parameters

$argsarray
Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
$instancearray
Settings for the current Archives widget instance.

Hooks fired · 4

4 hooks fire while WP_Widget_Archives::widget() runs, in this order:

  1. apply_filters( widget_title )filterline 48 (+5 into the body)

    Filters the widget title.

  2. apply_filters( widget_archives_dropdown_args )filterline 76 (+33 into the body)

    Filters the arguments for the Archives widget drop-down.

  3. apply_filters( navigation_widgets_format )filterline 128 (+85 into the body)

    Filters the HTML format of widgets with navigation links.

  4. apply_filters( widget_archives_args )filterline 152 (+109 into the body)

    Filters the arguments for the Archives widget.

Uses · 9

Source

	public function widget( $args, $instance ) {		$default_title = __( 'Archives' );		$title         = ! empty( $instance['title'] ) ? $instance['title'] : $default_title; 		/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 		$count    = ! empty( $instance['count'] ) ? '1' : '0';		$dropdown = ! empty( $instance['dropdown'] ) ? '1' : '0'; 		echo $args['before_widget']; 		if ( $title ) {			echo $args['before_title'] . $title . $args['after_title'];		} 		if ( $dropdown ) {			$dropdown_id = "{$this->id_base}-dropdown-{$this->number}";			?>		<label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label>		<select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown">			<?php			/**			 * Filters the arguments for the Archives widget drop-down.			 *			 * @since 2.8.0			 * @since 4.9.0 Added the `$instance` parameter.			 *			 * @see wp_get_archives()			 *			 * @param array $args     An array of Archives widget drop-down arguments.			 * @param array $instance Settings for the current Archives widget instance.			 */			$dropdown_args = apply_filters(				'widget_archives_dropdown_args',				array(					'type'            => 'monthly',					'format'          => 'option',					'show_post_count' => $count,				),				$instance			); 			switch ( $dropdown_args['type'] ) {				case 'yearly':					$label = __( 'Select Year' );					break;				case 'monthly':					$label = __( 'Select Month' );					break;				case 'daily':					$label = __( 'Select Day' );					break;				case 'weekly':					$label = __( 'Select Week' );					break;				default:					$label = __( 'Select Post' );					break;			}			?> 			<option value=""><?php echo esc_html( $label ); ?></option>			<?php wp_get_archives( $dropdown_args ); ?> 		</select> 			<?php ob_start(); ?><script>(function() {	var dropdown = document.getElementById( "<?php echo esc_js( $dropdown_id ); ?>" );	function onSelectChange() {		if ( dropdown.options[ dropdown.selectedIndex ].value !== '' ) {			document.location.href = this.options[ this.selectedIndex ].value;		}	}	dropdown.onchange = onSelectChange;})();</script>			<?php

History

Introduced in 2.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/widgets/class-wp-widget-archives.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.