-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
56 lines (51 loc) · 2.06 KB
/
search.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
<?php get_header(); ?>
<section class="articles-list">
<?php
$getSearchQuery = get_search_query();
$argsQuery = [
'post_type' => 'post',
's' => $getSearchQuery,
'order' => 'DESC',
'posts_per_page' => 10
];
$searchQuery = new WP_Query($argsQuery);
if ($searchQuery->have_posts()) {
?>
<div class="articles-list__title">
<h1>Risultati di ricerca per <?= get_search_query(); ?></h1>
</div>
<?php
while ($searchQuery->have_posts()) {
$searchQuery->the_post();
$searchPostUrl = get_permalink();
$searchPostTitle = get_the_title();
$searchPostImageUrl = get_the_post_thumbnail_url();
$searchPostImageAlt = get_post_meta(get_post_thumbnail_id( $post->ID ), '_wp_attachment_image_alt', true);
$searchPostContent = get_the_content();
$searchPostExcerp = substr($searchPostContent, 0, 200);
$searchPostExcerpNoHTML = strip_tags($searchPostExcerp);
?>
<a class="articles-list__container no-link" href="<?= $searchPostUrl; ?>">
<article class="articles-list__article">
<div class="articles-list__container-image">
<img class="articles-list__article-image" src="<?= $searchPostImageUrl; ?>" alt="<?= $searchPostImageAlt; ?>">
</div>
<div class="articles-list__content-container">
<h1 class="articles-list__article-title"><?= $searchPostTitle; ?></h1>
<div class="articles-list__article-paragraph"><?= $searchPostExcerpNoHTML; ?></div>
</div>
</article>
</a>
<?php
}
} else {
?>
<div class="articles-list__title">
<h1>Nessun risultato trovato con il termine <?= get_search_query(); ?></h1>
</div>
<?php
}
wp_reset_postdata();
?>
</section>
<?php get_footer(); ?>