/
template-tags.php
257 lines (231 loc) · 7.61 KB
/
template-tags.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
/**
* Custom template tags for this theme
*
* @package WordPress
* @subpackage Twenty_Twenty_One
* @since Twenty Twenty-One 1.0
*/
if ( ! function_exists( 'twenty_twenty_one_posted_on' ) ) {
/**
* Prints HTML with meta information for the current post-date/time.
*
* @since Twenty Twenty-One 1.0
*
* @return void
*/
function twenty_twenty_one_posted_on() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
$time_string = sprintf(
$time_string,
esc_attr( get_the_date( DATE_W3C ) ),
esc_html( get_the_date() )
);
echo '<span class="posted-on">';
printf(
/* translators: %s: Publish date. */
esc_html__( 'Published %s', 'twentytwentyone' ),
$time_string // phpcs:ignore WordPress.Security.EscapeOutput
);
echo '</span>';
}
}
if ( ! function_exists( 'twenty_twenty_one_posted_by' ) ) {
/**
* Prints HTML with meta information about theme author.
*
* @since Twenty Twenty-One 1.0
*
* @return void
*/
function twenty_twenty_one_posted_by() {
if ( ! get_the_author_meta( 'description' ) && post_type_supports( get_post_type(), 'author' ) ) {
echo '<span class="byline">';
printf(
/* translators: %s: Author name. */
esc_html__( 'By %s', 'twentytwentyone' ),
'<a href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '" rel="author">' . esc_html( get_the_author() ) . '</a>'
);
echo '</span>';
}
}
}
if ( ! function_exists( 'twenty_twenty_one_entry_meta_footer' ) ) {
/**
* Prints HTML with meta information for the categories, tags and comments.
* Footer entry meta is displayed differently in archives and single posts.
*
* @since Twenty Twenty-One 1.0
*
* @return void
*/
function twenty_twenty_one_entry_meta_footer() {
// Early exit if not a post.
if ( 'post' !== get_post_type() ) {
return;
}
// Hide meta information on pages.
if ( ! is_single() ) {
if ( is_sticky() ) {
echo '<p>' . esc_html_x( 'Featured post', 'Label for sticky posts', 'twentytwentyone' ) . '</p>';
}
$post_format = get_post_format();
if ( 'aside' === $post_format || 'status' === $post_format ) {
echo '<p><a href="' . esc_url( get_permalink() ) . '">' . twenty_twenty_one_continue_reading_text() . '</a></p>'; // phpcs:ignore WordPress.Security.EscapeOutput
}
// Posted on.
twenty_twenty_one_posted_on();
// Edit post link.
edit_post_link(
sprintf(
/* translators: %s: Name of current post. Only visible to screen readers. */
esc_html__( 'Edit %s', 'twentytwentyone' ),
'<span class="screen-reader-text">' . get_the_title() . '</span>'
),
'<span class="edit-link">',
'</span><br>'
);
if ( has_category() || has_tag() ) {
echo '<div class="post-taxonomies">';
/* translators: Used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'twentytwentyone' ) );
if ( $categories_list ) {
printf(
/* translators: %s: List of categories. */
'<span class="cat-links">' . esc_html__( 'Categorized as %s', 'twentytwentyone' ) . ' </span>',
$categories_list // phpcs:ignore WordPress.Security.EscapeOutput
);
}
/* translators: Used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'twentytwentyone' ) );
if ( $tags_list ) {
printf(
/* translators: %s: List of tags. */
'<span class="tags-links">' . esc_html__( 'Tagged %s', 'twentytwentyone' ) . '</span>',
$tags_list // phpcs:ignore WordPress.Security.EscapeOutput
);
}
echo '</div>';
}
} else {
echo '<div class="posted-by">';
// Posted on.
twenty_twenty_one_posted_on();
// Posted by.
twenty_twenty_one_posted_by();
// Edit post link.
edit_post_link(
sprintf(
/* translators: %s: Name of current post. Only visible to screen readers. */
esc_html__( 'Edit %s', 'twentytwentyone' ),
'<span class="screen-reader-text">' . get_the_title() . '</span>'
),
'<span class="edit-link">',
'</span>'
);
echo '</div>';
if ( has_category() || has_tag() ) {
echo '<div class="post-taxonomies">';
/* translators: Used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'twentytwentyone' ) );
if ( $categories_list ) {
printf(
/* translators: %s: List of categories. */
'<span class="cat-links">' . esc_html__( 'Categorized as %s', 'twentytwentyone' ) . ' </span>',
$categories_list // phpcs:ignore WordPress.Security.EscapeOutput
);
}
/* translators: Used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'twentytwentyone' ) );
if ( $tags_list ) {
printf(
/* translators: %s: List of tags. */
'<span class="tags-links">' . esc_html__( 'Tagged %s', 'twentytwentyone' ) . '</span>',
$tags_list // phpcs:ignore WordPress.Security.EscapeOutput
);
}
echo '</div>';
}
}
}
}
if ( ! function_exists( 'twenty_twenty_one_post_thumbnail' ) ) {
/**
* Displays an optional post thumbnail.
*
* Wraps the post thumbnail in an anchor element on index views, or a div
* element when on single views.
*
* @since Twenty Twenty-One 1.0
*
* @return void
*/
function twenty_twenty_one_post_thumbnail() {
if ( ! twenty_twenty_one_can_show_post_thumbnail() ) {
return;
}
?>
<?php if ( is_singular() ) : ?>
<figure class="post-thumbnail">
<?php
// Lazy-loading attributes should be skipped for thumbnails since they are immediately in the viewport.
the_post_thumbnail( 'post-thumbnail', array( 'loading' => false ) );
?>
<?php if ( wp_get_attachment_caption( get_post_thumbnail_id() ) ) : ?>
<figcaption class="wp-caption-text"><?php echo wp_kses_post( wp_get_attachment_caption( get_post_thumbnail_id() ) ); ?></figcaption>
<?php endif; ?>
</figure><!-- .post-thumbnail -->
<?php else : ?>
<figure class="post-thumbnail">
<a class="post-thumbnail-inner alignwide" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
<?php the_post_thumbnail( 'post-thumbnail' ); ?>
</a>
<?php if ( wp_get_attachment_caption( get_post_thumbnail_id() ) ) : ?>
<figcaption class="wp-caption-text"><?php echo wp_kses_post( wp_get_attachment_caption( get_post_thumbnail_id() ) ); ?></figcaption>
<?php endif; ?>
</figure>
<?php endif; ?>
<?php
}
}
if ( ! function_exists( 'twenty_twenty_one_the_posts_navigation' ) ) {
/**
* Print the next and previous posts navigation.
*
* @since Twenty Twenty-One 1.0
*
* @return void
*/
function twenty_twenty_one_the_posts_navigation() {
the_posts_pagination(
array(
'before_page_number' => esc_html__( 'Page', 'twentytwentyone' ) . ' ',
'mid_size' => 0,
'prev_text' => sprintf(
'%s <span class="nav-prev-text">%s</span>',
is_rtl() ? twenty_twenty_one_get_icon_svg( 'ui', 'arrow_right' ) : twenty_twenty_one_get_icon_svg( 'ui', 'arrow_left' ),
wp_kses(
__( 'Newer <span class="nav-short">posts</span>', 'twentytwentyone' ),
array(
'span' => array(
'class' => array(),
),
)
)
),
'next_text' => sprintf(
'<span class="nav-next-text">%s</span> %s',
wp_kses(
__( 'Older <span class="nav-short">posts</span>', 'twentytwentyone' ),
array(
'span' => array(
'class' => array(),
),
)
),
is_rtl() ? twenty_twenty_one_get_icon_svg( 'ui', 'arrow_left' ) : twenty_twenty_one_get_icon_svg( 'ui', 'arrow_right' )
),
)
);
}
}