-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
266 lines (181 loc) · 6.74 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
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
<?php
/**
* The template for displaying search results pages
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
*
* @package cap2019
*/
get_header();
// $paged - number of the current page
global $paged, $wp_query;
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
?>
<div id="primary" class="primary primary--search content-area">
<main id="main" class="site-main container">
<div class="cap-search__main flex-container">
<div class="cap-search__posts flex-item">
<?php
if ( have_posts() ) : ?>
<header class="page-header">
<h1 class="page-title">
<?php
/* translators: %s: search query. */
printf( esc_html__( 'Search Results for: %s', 'cap' ), '<span>' . get_search_query() . '</span>' );
?>
</h1>
</header><!-- .page-header -->
<div class="wrap--no-stickies <?php if ( empty( $search_stickies ) ) echo ' beware-no-stickies'; ?>">
<div class="no-stickies">
<?php
$unst_i = 0;
while ( have_posts() ) :
the_post();
$ID = get_the_ID();
$title = get_the_title( $ID );
if ( has_excerpt( $ID ) ) :
if ( ctype_space( get_the_excerpt( $ID ) ) ) :
$excerpt = $post->post_content;
// Remove iframe from string
$excerpt = preg_replace('/<iframe.*?\/iframe>/i','', $excerpt);
$excerpt = wp_strip_all_tags(
cap_custom_excerpt(
$excerpt,
50,
get_permalink(),
''
)
);
else:
$excerpt = wpautop( $post->post_excerpt );
endif;
else :
$excerpt = $post->post_content;
// Remove iframe from string
$excerpt = preg_replace('/<iframe.*?\/iframe>/i','', $excerpt);
$excerpt = wp_strip_all_tags(
cap_custom_excerpt(
$excerpt,
50,
get_permalink(),
''
)
);
endif;
$permalink = get_the_permalink( $ID );
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $ID ), 'cap-single-thumbnail' );
$thumb = filter_var( $thumb[0], FILTER_VALIDATE_URL )
? $thumb[0]
: get_template_directory_uri() . '/img/default-thumb.jpg';
$countries = get_the_terms( $ID, 'country' );
$has_countries = ( $countries && !is_wp_error( $countries ) );
$list_cats_Arr = wp_get_post_categories(
$ID,
array(
'fields' => 'names',
)
);
$has_cats = (
( count( $list_cats_Arr ) > 1 ) ||
(
( count( $list_cats_Arr ) == 1 ) &&
( 'Uncategorized' !== $list_cats_Arr[0] )
)
);
?>
<div class="no-sticky flex-container <?php echo 'no-sticky--' . $unst_i; ?> <?php echo 'pt--' . get_post_type(); ?>">
<div class="no-sticky__left flex-item">
<div class="no-sticky__meta flex-container">
<?php if ( $has_cats ) : ?>
<div class="entry-meta__post-cats flex-item flex-container">
<?php cap_post_cats( 3, false ); ?>
</div>
<?php endif;
if ( $has_countries ) : ?>
<div class="entry-meta__post-countries flex-item flex-container">
<?php cap_post_countries(); ?>
</div>
<?php
endif; ?>
</div>
<h2 class="no-sticky__title"><a href="<?php echo $permalink; ?>"><?php echo relevanssi_get_the_title( $ID ); ?></a></h2>
<div class="no-sticky__excerpt"><?php echo $excerpt; ?></div>
</div>
<div class="no-sticky__right flex-item">
<div class="wrap--no-sticky__thumb">
<div class="no-sticky__thumb">
<a href="<?php echo $permalink; ?>" style="background: transparent url('<?php echo $thumb; ?>') center center/cover no-repeat;"></a>
</div>
</div>
</div>
</div>
<?php
if ( ( $unst_i == 4 ) && ( $paged == 1 ) ) :
$btitle = get_field( 'cap_general_arch_cobustitle', 'option' );
$btitle = ( $btitle && ( '' !== $btitle ) )
? $btitle
: false;
cap_blog_inbetween_cobus( false, $btitle );
endif;
$unst_i++;
endwhile;
wp_reset_postdata();
/**
* PAGINATION
* ==========
*/
// $paged is defined at the top - it's needed elsewhere as
// well in the code, not only in pagination.
$total_pages = $wp_query->max_num_pages;
$big = 999999999; // need an unlikely integer
$current_page = max(1, $paged);
$pargs = array(
'prev_text' => '<span class="cap-pagination__prev dashicons dashicons-arrow-left-alt2"></span>',
'next_text' => '<span class="cap-pagination__prev dashicons dashicons-arrow-right-alt2"></span>',
// Using 'type' => 'array' you can remove
// page links by using unset().
// E.g.: unset( $links[ $total_pages - 7 ] ) -
// just don't forget to set the $total_pages
// value, see below;
'type' => 'array',
'mid_size' => 1,
'end_size' => 1,
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => $current_page,
'total' => $total_pages,
'paged' => $paged,
);
if ($total_pages > 1) :
$links = paginate_links($pargs);
echo '<div class="wrap--cap-pagination"><div class="cap-pagination">';
// Add "Page x of X" info span
echo "<span class='page-numbers pageof-info'>Page {$paged} of {$total_pages}</span>";
foreach ( $links as $link ) echo $link;
echo '</div></div>';
endif;
?>
</div>
</div>
<?php
else: ?>
<header class="page-header">
<h1 class="page-title">
<?php
/* translators: %s: search query. */
printf( esc_html__( 'Search Results for: %s', 'cap' ), '<span>' . get_search_query() . '</span>' );
?>
</h1>
<div class="page-description"><?php esc_html_e( 'Nothing Found :(', 'cap' ); ?></div>
</header><!-- .page-header -->
<?php
endif; ?>
</div>
<div class="cap-search__sidebar flex-item">
<?php get_sidebar('cpt-archive'); ?>
</div>
</div>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();