equal
deleted
inserted
replaced
15 * @return string Returns the post content with archives added. |
15 * @return string Returns the post content with archives added. |
16 */ |
16 */ |
17 function render_block_core_archives( $attributes ) { |
17 function render_block_core_archives( $attributes ) { |
18 $show_post_count = ! empty( $attributes['showPostCounts'] ); |
18 $show_post_count = ! empty( $attributes['showPostCounts'] ); |
19 |
19 |
20 $class = 'wp-block-archives'; |
20 $class = ''; |
21 |
|
22 if ( isset( $attributes['align'] ) ) { |
|
23 $class .= " align{$attributes['align']}"; |
|
24 } |
|
25 |
|
26 if ( isset( $attributes['className'] ) ) { |
|
27 $class .= " {$attributes['className']}"; |
|
28 } |
|
29 |
21 |
30 if ( ! empty( $attributes['displayAsDropdown'] ) ) { |
22 if ( ! empty( $attributes['displayAsDropdown'] ) ) { |
31 |
23 |
32 $class .= ' wp-block-archives-dropdown'; |
24 $class .= ' wp-block-archives-dropdown'; |
33 |
25 |
64 default: |
56 default: |
65 $label = __( 'Select Post' ); |
57 $label = __( 'Select Post' ); |
66 break; |
58 break; |
67 } |
59 } |
68 |
60 |
69 $label = esc_attr( $label ); |
61 $label = esc_html( $label ); |
70 |
62 |
71 $block_content = '<label class="screen-reader-text" for="' . $dropdown_id . '">' . $title . '</label> |
63 $block_content = '<label class="screen-reader-text" for="' . $dropdown_id . '">' . $title . '</label> |
72 <select id="' . $dropdown_id . '" name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"> |
64 <select id="' . $dropdown_id . '" name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"> |
73 <option value="">' . $label . '</option>' . $archives . '</select>'; |
65 <option value="">' . $label . '</option>' . $archives . '</select>'; |
74 |
66 |
94 |
86 |
95 $archives = wp_get_archives( $archives_args ); |
87 $archives = wp_get_archives( $archives_args ); |
96 |
88 |
97 $classnames = esc_attr( $class ); |
89 $classnames = esc_attr( $class ); |
98 |
90 |
|
91 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) ); |
|
92 |
99 if ( empty( $archives ) ) { |
93 if ( empty( $archives ) ) { |
100 |
|
101 return sprintf( |
94 return sprintf( |
102 '<div class="%1$s">%2$s</div>', |
95 '<div %1$s>%2$s</div>', |
103 $classnames, |
96 $wrapper_attributes, |
104 __( 'No archives to show.' ) |
97 __( 'No archives to show.' ) |
105 ); |
98 ); |
106 } |
99 } |
107 |
100 |
108 return sprintf( |
101 return sprintf( |
109 '<ul class="%1$s">%2$s</ul>', |
102 '<ul %1$s>%2$s</ul>', |
110 $classnames, |
103 $wrapper_attributes, |
111 $archives |
104 $archives |
112 ); |
105 ); |
113 } |
106 } |
114 |
107 |
115 /** |
108 /** |