-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpage-artigos.php
More file actions
328 lines (267 loc) · 10.3 KB
/
page-artigos.php
File metadata and controls
328 lines (267 loc) · 10.3 KB
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<?php
get_header();
?>
<div class="container-header">
<div class="content-header">
<div class="title">
<h1>Artigos</h1>
</div>
</div>
</div>
<div class="container">
<?php
$ano_get = isset($_GET['ano']) ? sanitize_text_field($_GET['ano']) : '';
$autor_get = isset($_GET['autor']) ? sanitize_text_field($_GET['autor']) : '';
$evento_get = isset($_GET['evento']) ? sanitize_text_field($_GET['evento']) : '';
$buscar_get = isset($_GET['buscar']) ? sanitize_text_field($_GET['buscar']) : '';
?>
<form id="filter-form" method="get" action="<?php echo esc_url(get_permalink()); ?>">
<div class="artigos-filters">
<div class="filter-group">
<label for="filter-ano">Ano</label>
<select id="filter-ano" name="ano">
<option value="">Todos</option>
<?php
$anos = get_terms(array(
'taxonomy' => 'ano_artigo',
'hide_empty' => true,
'order' => 'DESC'
));
foreach ($anos as $term) {
$selected = ($ano_get == $term->slug) ? 'selected' : '';
echo '<option value="' . esc_attr($term->slug) . '" ' . $selected . '>' . esc_html($term->name) . '</option>';
}
?>
</select>
</div>
<div class="filter-group">
<label for="filter-autor">Autor</label>
<select id="filter-autor" name="autor">
<option value="">Todos os autores</option>
<?php
$artigos_posts = get_posts(array(
'post_type' => 'artigo',
'posts_per_page' => -1,
'fields' => 'ids',
'post_status' => 'publish'
));
$autores_ids = array();
foreach ($artigos_posts as $artigo_id) {
$autores_artigo = get_post_meta($artigo_id, '_artigo_autores', true);
if (is_array($autores_artigo)) {
$autores_ids = array_merge($autores_ids, $autores_artigo);
}
}
$autores_ids = array_unique($autores_ids);
if (!empty($autores_ids)) {
$autores = get_posts(array(
'post_type' => 'membro',
'numberposts' => -1,
'orderby' => 'title',
'order' => 'ASC',
'include' => $autores_ids
));
foreach ($autores as $autor) {
$selected = ($autor_get == $autor->ID) ? 'selected' : '';
echo '<option value="' . $autor->ID . '" ' . $selected . '>' . esc_html($autor->post_title) . '</option>';
}
}
?>
</select>
</div>
<div class="filter-group">
<label for="filter-evento">Evento</label>
<select id="filter-evento" name="evento">
<option value="">Todos os eventos</option>
<?php
$eventos = get_terms(array(
'taxonomy' => 'evento_artigo',
'hide_empty' => true,
));
if (!is_wp_error($eventos) && !empty($eventos)) {
foreach ($eventos as $evento) {
$selected = ($evento_get == $evento->slug) ? 'selected' : '';
echo '<option value="' . esc_attr($evento->slug) . '" ' . $selected . '>' . esc_html($evento->name) . '</option>';
}
}
?>
</select>
</div>
<div class="filter-group search-group">
<label for="filter-buscar">Buscar</label>
<input type="text" id="filter-buscar" name="buscar" placeholder="Busque o termo desejado" value="<?php echo esc_attr($buscar_get); ?>">
</div>
<button type="submit" class="filter-btn">Filtrar</button>
</div>
</form>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'artigo',
'posts_per_page' => 5,
'paged' => $paged,
'orderby' => 'date',
'order' => 'DESC',
'tax_query' => array('relation' => 'AND'),
);
$meta_query = array('relation' => 'AND');
if ($ano_get) {
$args['tax_query'][] = array(
'taxonomy' => 'ano_artigo',
'field' => 'slug',
'terms' => $ano_get,
);
}
if ($autor_get) {
$meta_query[] = array(
'relation' => 'OR',
array(
'key' => '_artigo_autores',
'value' => '"' . $autor_get . '"',
'compare' => 'LIKE'
),
array(
'key' => '_artigo_autores',
'value' => ':' . $autor_get . ';',
'compare' => 'LIKE'
)
);
}
if (count($meta_query) > 1) {
$args['meta_query'] = $meta_query;
}
if ($evento_get) {
$args['tax_query'][] = array(
'taxonomy' => 'evento_artigo',
'field' => 'slug',
'terms' => $evento_get,
);
}
if ($buscar_get) {
$args['s'] = $buscar_get;
}
$artigos_query = new WP_Query($args);
?>
<div class="artigos-container" id="artigos-results">
<?php
$artigos_query = new WP_Query($args);
$base_url = get_permalink();
?>
<div class="artigos-container" id="artigos-results">
<?php
if ($artigos_query->have_posts()) :
while ($artigos_query->have_posts()) : $artigos_query->the_post();
$anos_term = get_the_terms(get_the_ID(), 'ano_artigo');
$ano_label = date('Y');
$ano_link = null;
if (!empty($anos_term) && !is_wp_error($anos_term)) {
$ano_label = $anos_term[0]->name;
$ano_link = add_query_arg('ano', $anos_term[0]->slug, $base_url);
}
$eventos_term = get_the_terms(get_the_ID(), 'evento_artigo');
$evento_label = 'SBC BRASIL';
$evento_link = null;
if (!empty($eventos_term) && !is_wp_error($eventos_term)) {
$evento_label = $eventos_term[0]->name;
$evento_link = add_query_arg('evento', $eventos_term[0]->slug, $base_url);
}
$premio = get_post_meta(get_the_ID(), 'premio', true);
$link_externo = get_post_meta(get_the_ID(), '_link_externo_artigo', true);
$link_artigo_destino = !empty($link_externo) ? $link_externo : get_permalink(get_the_ID());
$target_link = !empty($link_externo) ? '_blank' : '_self';
$rel_link = !empty($link_externo) ? 'noopener noreferrer' : '';
?>
<article class="artigo-card">
<div class="artigo-badges">
<?php if ($ano_link) : ?>
<a href="<?php echo esc_url($ano_link); ?>" class="badge ano-badge" title="Filtrar por <?php echo esc_attr($ano_label); ?>">
<?php echo esc_html($ano_label); ?>
</a>
<?php else : ?>
<span class="badge ano-badge"><?php echo esc_html($ano_label); ?></span>
<?php endif; ?>
<?php if ($evento_link) : ?>
<a href="<?php echo esc_url($evento_link); ?>" class="badge evento-badge" title="Filtrar por <?php echo esc_attr($evento_label); ?>">
<?php echo esc_html($evento_label); ?>
</a>
<?php else : ?>
<span class="badge evento-badge"><?php echo esc_html($evento_label); ?></span>
<?php endif; ?>
<?php if ($premio) : ?>
<span class="badge premio-badge">🥇 <?php echo esc_html($premio); ?></span>
<?php endif; ?>
</div>
<div class="artigo-content">
<h2 class="artigo-title">
<a href="<?php echo esc_url($link_artigo_destino); ?>"
target="<?php echo $target_link; ?>"
<?php if ($rel_link) echo 'rel="' . $rel_link . '"'; ?>>
<?php the_title(); ?>
</a>
</h2>
<div class="artigo-excerpt">
<?php
$content = strip_shortcodes(strip_tags(get_the_content()));
$paragraphs = array_filter(explode("\n\n", $content));
foreach (array_slice($paragraphs, 0, 2) as $p) {
echo '<p>' . trim($p) . '</p>';
}
?>
</div>
<?php
$autores_ids = get_post_meta(get_the_ID(), '_artigo_autores', true);
if (!empty($autores_ids) && is_array($autores_ids)) :
?>
<div class="artigo-autores">
<?php foreach ($autores_ids as $autor_id) :
$autor_nome = get_the_title($autor_id);
$autor_foto_url = get_the_post_thumbnail_url($autor_id, 'thumbnail');
$autor_link = add_query_arg('autor', $autor_id, $base_url);
?>
<div class="autor-avatar">
<div class="avatar-circle">
<?php if ($autor_foto_url) : ?>
<img src="<?php echo esc_url($autor_foto_url); ?>" alt="<?php echo esc_attr($autor_nome); ?>">
<?php else : ?>
<?php echo strtoupper(substr($autor_nome, 0, 1)); ?>
<?php endif; ?>
</div>
<a href="<?php echo esc_url($autor_link); ?>" class="autor-link autor-nome" title="Ver artigos de <?php echo esc_attr($autor_nome); ?>">
<?php echo esc_html($autor_nome); ?>
</a>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</article>
<?php
endwhile;
wp_reset_postdata();
else : ?>
<p class="no-articles">Não há artigos disponíveis no momento.</p>
<?php endif; ?>
</div>
</div>
<?php
if ($artigos_query->max_num_pages > 1) {
echo '<div class="artigos-pagination">';
echo paginate_links(array(
'base' => str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $artigos_query->max_num_pages,
'prev_text' => __('« Anterior'),
'next_text' => __('Próximo »'),
'add_args' => array_filter(array(
'ano' => $ano_get,
'autor' => $autor_get,
'evento' => $evento_get,
'buscar' => $buscar_get,
)),
));
echo '</div>';
}
?>
</div>
<?php get_footer(); ?>