38 * @param array $args Display arguments including 'before_title', 'after_title', |
38 * @param array $args Display arguments including 'before_title', 'after_title', |
39 * 'before_widget', and 'after_widget'. |
39 * 'before_widget', and 'after_widget'. |
40 * @param array $instance Settings for the current Archives widget instance. |
40 * @param array $instance Settings for the current Archives widget instance. |
41 */ |
41 */ |
42 public function widget( $args, $instance ) { |
42 public function widget( $args, $instance ) { |
43 $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Archives' ); |
43 $default_title = __( 'Archives' ); |
|
44 $title = ! empty( $instance['title'] ) ? $instance['title'] : $default_title; |
44 |
45 |
45 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
46 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
46 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
47 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
47 |
48 |
48 $c = ! empty( $instance['count'] ) ? '1' : '0'; |
49 $count = ! empty( $instance['count'] ) ? '1' : '0'; |
49 $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; |
50 $dropdown = ! empty( $instance['dropdown'] ) ? '1' : '0'; |
50 |
51 |
51 echo $args['before_widget']; |
52 echo $args['before_widget']; |
52 |
53 |
53 if ( $title ) { |
54 if ( $title ) { |
54 echo $args['before_title'] . $title . $args['after_title']; |
55 echo $args['before_title'] . $title . $args['after_title']; |
55 } |
56 } |
56 |
57 |
57 if ( $d ) { |
58 if ( $dropdown ) { |
58 $dropdown_id = "{$this->id_base}-dropdown-{$this->number}"; |
59 $dropdown_id = "{$this->id_base}-dropdown-{$this->number}"; |
59 ?> |
60 ?> |
60 <label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label> |
61 <label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label> |
61 <select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown"> |
62 <select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown"> |
62 <?php |
63 <?php |
74 $dropdown_args = apply_filters( |
75 $dropdown_args = apply_filters( |
75 'widget_archives_dropdown_args', |
76 'widget_archives_dropdown_args', |
76 array( |
77 array( |
77 'type' => 'monthly', |
78 'type' => 'monthly', |
78 'format' => 'option', |
79 'format' => 'option', |
79 'show_post_count' => $c, |
80 'show_post_count' => $count, |
80 ), |
81 ), |
81 $instance |
82 $instance |
82 ); |
83 ); |
83 |
84 |
84 switch ( $dropdown_args['type'] ) { |
85 switch ( $dropdown_args['type'] ) { |
96 break; |
97 break; |
97 default: |
98 default: |
98 $label = __( 'Select Post' ); |
99 $label = __( 'Select Post' ); |
99 break; |
100 break; |
100 } |
101 } |
|
102 |
|
103 $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : ' type="text/javascript"'; |
101 ?> |
104 ?> |
102 |
105 |
103 <option value=""><?php echo esc_attr( $label ); ?></option> |
106 <option value=""><?php echo esc_attr( $label ); ?></option> |
104 <?php wp_get_archives( $dropdown_args ); ?> |
107 <?php wp_get_archives( $dropdown_args ); ?> |
105 |
108 |
106 </select> |
109 </select> |
107 |
110 |
108 <script type='text/javascript'> |
111 <script<?php echo $type_attr; ?>> |
109 /* <![CDATA[ */ |
112 /* <![CDATA[ */ |
110 (function() { |
113 (function() { |
111 var dropdown = document.getElementById( "<?php echo esc_js( $dropdown_id ); ?>" ); |
114 var dropdown = document.getElementById( "<?php echo esc_js( $dropdown_id ); ?>" ); |
112 function onSelectChange() { |
115 function onSelectChange() { |
113 if ( dropdown.options[ dropdown.selectedIndex ].value !== '' ) { |
116 if ( dropdown.options[ dropdown.selectedIndex ].value !== '' ) { |
116 } |
119 } |
117 dropdown.onchange = onSelectChange; |
120 dropdown.onchange = onSelectChange; |
118 })(); |
121 })(); |
119 /* ]]> */ |
122 /* ]]> */ |
120 </script> |
123 </script> |
121 |
|
122 <?php } else { ?> |
|
123 <ul> |
|
124 <?php |
124 <?php |
125 /** |
125 } else { |
126 * Filters the arguments for the Archives widget. |
126 $format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml'; |
127 * |
127 |
128 * @since 2.8.0 |
128 /** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */ |
129 * @since 4.9.0 Added the `$instance` parameter. |
129 $format = apply_filters( 'navigation_widgets_format', $format ); |
130 * |
130 |
131 * @see wp_get_archives() |
131 if ( 'html5' === $format ) { |
132 * |
132 // The title may be filtered: Strip out HTML and make sure the aria-label is never empty. |
133 * @param array $args An array of Archives option arguments. |
133 $title = trim( strip_tags( $title ) ); |
134 * @param array $instance Array of settings for the current widget. |
134 $aria_label = $title ? $title : $default_title; |
135 */ |
135 echo '<nav role="navigation" aria-label="' . esc_attr( $aria_label ) . '">'; |
136 wp_get_archives( |
136 } |
137 apply_filters( |
|
138 'widget_archives_args', |
|
139 array( |
|
140 'type' => 'monthly', |
|
141 'show_post_count' => $c, |
|
142 ), |
|
143 $instance |
|
144 ) |
|
145 ); |
|
146 ?> |
137 ?> |
147 </ul> |
138 |
|
139 <ul> |
|
140 <?php |
|
141 wp_get_archives( |
|
142 /** |
|
143 * Filters the arguments for the Archives widget. |
|
144 * |
|
145 * @since 2.8.0 |
|
146 * @since 4.9.0 Added the `$instance` parameter. |
|
147 * |
|
148 * @see wp_get_archives() |
|
149 * |
|
150 * @param array $args An array of Archives option arguments. |
|
151 * @param array $instance Array of settings for the current widget. |
|
152 */ |
|
153 apply_filters( |
|
154 'widget_archives_args', |
|
155 array( |
|
156 'type' => 'monthly', |
|
157 'show_post_count' => $count, |
|
158 ), |
|
159 $instance |
|
160 ) |
|
161 ); |
|
162 ?> |
|
163 </ul> |
|
164 |
148 <?php |
165 <?php |
|
166 if ( 'html5' === $format ) { |
|
167 echo '</nav>'; |
|
168 } |
149 } |
169 } |
150 |
170 |
151 echo $args['after_widget']; |
171 echo $args['after_widget']; |
152 } |
172 } |
153 |
173 |
193 'count' => 0, |
213 'count' => 0, |
194 'dropdown' => '', |
214 'dropdown' => '', |
195 ) |
215 ) |
196 ); |
216 ); |
197 ?> |
217 ?> |
198 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /></p> |
|
199 <p> |
218 <p> |
200 <input class="checkbox" type="checkbox"<?php checked( $instance['dropdown'] ); ?> id="<?php echo $this->get_field_id( 'dropdown' ); ?>" name="<?php echo $this->get_field_name( 'dropdown' ); ?>" /> <label for="<?php echo $this->get_field_id( 'dropdown' ); ?>"><?php _e( 'Display as dropdown' ); ?></label> |
219 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> |
|
220 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /> |
|
221 </p> |
|
222 <p> |
|
223 <input class="checkbox" type="checkbox"<?php checked( $instance['dropdown'] ); ?> id="<?php echo $this->get_field_id( 'dropdown' ); ?>" name="<?php echo $this->get_field_name( 'dropdown' ); ?>" /> |
|
224 <label for="<?php echo $this->get_field_id( 'dropdown' ); ?>"><?php _e( 'Display as dropdown' ); ?></label> |
201 <br/> |
225 <br/> |
202 <input class="checkbox" type="checkbox"<?php checked( $instance['count'] ); ?> id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" /> <label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e( 'Show post counts' ); ?></label> |
226 <input class="checkbox" type="checkbox"<?php checked( $instance['count'] ); ?> id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" /> |
|
227 <label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e( 'Show post counts' ); ?></label> |
203 </p> |
228 </p> |
204 <?php |
229 <?php |
205 } |
230 } |
206 } |
231 } |