-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.php
112 lines (104 loc) · 3.65 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
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
<?php
/**
* The search results page
* This is the template file to display search results.
* It is used to display a a list of pages / posts matching a search query.
* Each result is presented in its own promo panel at 1/3 width.
* The sidebar is intentionally disabled on this view, regardless of site settings.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
* @package Hale
* @copyright Ministry of Justice
* @version 2.0
*/
get_header();
?>
<div id="primary" class="govuk-grid-column-two-thirds">
<header class="hale-search-header" style="">
<h1 style="line-height:0;">
<span class="govuk-heading-xl govuk-!-margin-bottom-0">
<?php _e("Search Results","hale");?>
</span>
<br />
<span class="govuk-body-l">
<?php
/* translators: %s: search term */
if (get_search_query() == "") {
_e("No search words entered","hale");
} else {
$search_query_HTML = esc_html(get_search_query());
echo sprintf(__('for %s', 'hale' ), $search_query_HTML);
}
$header_search = get_theme_mod( 'show_search', 'yes' );
?>
</span>
</h1>
<?php get_search_form(); ?>
</header>
<div class="index">
<?php
if ( have_posts() ) :
?>
<h2 class="govuk-heading-m">
<?php /* Search Count */
echo sprintf(__('%s results', 'hale' ), $wp_query->found_posts);
?>
</h2>
<div class="hale-search-results">
<?php
/* Start the Loop */
while ( have_posts() ) :
the_post();
?>
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible">
<div class="hale-search-result__item">
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail( 'thumbnail', [ 'class' => 'hale-promo__image' ] );
else :
$fallback = get_theme_mod( 'blog_fallback' );
if ( $fallback ) {
echo wp_get_attachment_image( $fallback, 'thumbnail', false, [ 'class' => 'hale-promo__image' ] );
}
endif;
?>
<h3 class="govuk-heading-m">
<a class="govuk-link" href="<?php the_permalink(); ?>">
<?php echo strip_tags(get_the_title()); ?>
</a>
</h2>
<?php do_action( 'hale_before_archive_content' ); ?>
<p class="govuk-body">
<?php
$excerpt = get_the_excerpt();
if(!empty($s)) {
$keys = explode(' ', $s);
$excerpt = preg_replace('/(' . implode('|', $keys) . ')/iu', '<span class="search-terms">\0</span>', $excerpt);
}
echo $excerpt; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</p>
<?php do_action( 'hale_after_archive_content' ); ?>
<?php
// Get and display the last updated time of the search result
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
echo "<p class='govuk-body hale-search-results__last-updated-date'>";
echo sprintf(__('Updated on %s', 'hale' ), get_the_modified_time('j<\s\up>S</\s\up> F Y'));
echo "</p> ";
?>
</div>
<?php
endwhile;
?>
</div>
<?php
hale_archive_pagination();
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
</div>
</div><!-- #primary -->
<?php
get_footer();