-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
69 lines (64 loc) · 2.84 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
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php get_header(); ?>
<main class="container mt-5">
<div class="row">
<div class="col-md-8">
<header class="page-header mb-4">
<h1 class="page-title">
<?php
if (have_posts()) :
printf('Search Results for: %s', get_search_query());
else :
echo 'No results found';
endif;
?>
</h1>
</header>
<?php
// Start the loop for search results
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<div class="col-md-6 mb-4">
<div class="card">
<?php if (has_post_thumbnail()) : ?>
<div class="position-relative">
<a href="<?php the_permalink(); ?>">
<img width="388" height="221" src="<?php the_post_thumbnail_url('archive-banner'); ?>" class="card-img-top" alt="<?php the_title_attribute(); ?>">
</a>
<?php
$categories = get_the_category();
if (!empty($categories)) {
echo '<span class="badge bg-primary position-absolute top-0 start-0 m-2">' . esc_html($categories[0]->name) . '</span>';
}
?>
</div>
<?php endif; ?>
<div class="bg-dark text-white p-2">
<?php echo get_the_date(); ?>
</div>
<div class="card-body">
<h2 class="card-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="card-text"><?php echo wp_trim_words(get_the_excerpt(), 20, '...'); ?></p>
</div>
</div>
</div>
<?php endwhile;
else :
?>
<p><?php esc_html_e('Sorry, no posts matched your criteria.', 'speedpress'); ?></p>
<?php endif; ?>
<?php
// Pagination
the_posts_pagination(array(
'prev_text' => '« ' . esc_html__('Previous', 'speedpress'),
'next_text' => esc_html__('Next', 'speedpress') . ' »',
));
?>
</div>
<div class="col-md-4">
<div class="sidebar">
<?php get_sidebar(); ?>
</div>
</div>
</div>
</main>
<?php get_footer(); ?>