-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.php
176 lines (153 loc) · 6.95 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
<?php
get_header();
global $helpers;
$search_query = trim( get_search_query() );
?>
<main role="main" class="container-fluid m-0 p-0">
<div class="container">
<h1 class="post-title"><?php
$found_posts = $wp_query->found_posts;
$title = '';
if ( $found_posts === 0 ){
$title = "Nothing found for <em>$search_query</em>";
} elseif ( $found_posts === 1 ) {
$title = "One result found for <em>$search_query</em>";
} else {
$title = number_format( $found_posts ) . " results found for <em>$search_query</em>";
}
echo $title;
?></h1>
<div class="post-content">
<?php
get_search_form( true );
if ( in_array( $search_query, [ 'twitter', 'twitter bot', 'twitterbot', 'twitter bots', 'twitterbots', 'tweet' ] ) ){ ?>
<p><a class="btn" href="/bots/twitterbots/">Browse Twitter bots</a></p>
<?php }
get_template_part( 'loop' );
$possible_tags = explode( ' ', $search_query );
$tags_html = array();
foreach ( $possible_tags as $tag ) {
/*
TODO: Very basic pluralization, consider refactoring in the future.
*/
if ( substr( $tag, -1) === 's' ){
$tag_singular = substr( $tag, 0, -1 );;
$tag_plural = $tag;
} else {
$tag_singular = $tag;
$tag_plural = $tag . 's';
}
if ( term_exists( $tag_singular, 'post_tag' ) ){
$tags_html[] = "<a href='/tag/$tag_singular'>$tag_singular</a> ";
}
if ( term_exists( $tag_plural, 'post_tag' ) ){
$tags_html[] = "<a href='/tag/$tag_plural'>$tag_plural</a> ";
}
}
if ( $tags_html ){
echo '<p class="lead mt-5 "><strong class="mr-3">Related tags</strong></p><p class="post-tags mb-5">';
echo( implode( '', $tags_html ) );
echo '</p>';
}
if ($wp_query->found_posts > 0){
get_template_part( 'pagination' );
?>
<h3>Not quite what you're looking for?</h3>
<?php }?>
<div class="container">
<ul>
<li>
<a title="Add your bot, tutorial, and other botmaking resources to Botwiki" href="<?php echo home_url(); ?>/contribute/">Contribute to Botwiki</a>
<ul>
<li><em>Please be patient while we review the submissions</em> <span title="Thank you!">🙇</span></li>
</ul>
</li>
<li>
<a href="https://botmakers.org/">Ask in the Botmakers community</a>
</li>
<li>
<a href="mailto:<?php echo $helpers->get_admin_emails(); ?>">Send us an email</a>
</li>
<li>
<a href="https://mastodon.social/@botwiki">Find us on Mastodon</a>
</li>
</ul>
</div>
<div class="container">
<h3 id="bots">Latest bots</h3>
<div id="bots-latest-wrapper" class="row list">
<?php
remove_all_filters( 'pre_get_posts' );
$latest_bots = get_posts( array(
'posts_per_page' => 4,
'post_type' => 'bot',
'post_status' => 'publish'
) );
foreach ( $latest_bots as $bot ) {
$post_thumbnail_url = get_the_post_thumbnail_url( $bot->ID, 'large' );
$post_thumbnail_url_full = get_the_post_thumbnail_url( $bot->ID );
$dominant_color = get_post_meta( $bot->ID, 'dominant_color', true );
$dominant_color_css = str_replace('[', 'background-color:rgb(', $dominant_color);
$dominant_color_css = str_replace(']', ')', $dominant_color_css);
?>
<div class="col-sm-6 col-md-6 col-lg-3 list-item">
<div class="card w-100">
<a href="<?php echo get_permalink( $bot->ID ); ?>">
<div class="overflow-hidden" style="<?php echo $dominant_color_css; ?>">
<img loading="lazy" class="lazy-load card-img-top" src="<?php echo $post_thumbnail_url; ?>" data-src="<?php echo $post_thumbnail_url_full; ?>" alt="<?php echo $bot->post_title; ?>">
</div>
</a>
<div class="card-body">
<h5 class="card-title">
<a class="stretched-link" href="<?php echo get_permalink( $bot->ID ); ?>"><?php echo $bot->post_title; ?></a>
</h5>
<p class="card-text"><?php echo $bot->post_excerpt; ?></p>
</div>
</div>
</div>
<?php } ?>
</div>
<p><a class="btn" href="/bots/">Explore</a></p>
<!-- /post details -->
</div>
<div class="container">
<h3 id="blog">Latest from the blog</h3>
<div id="blog-latest-wrapper" class="row list">
<?php
remove_all_filters( 'pre_get_posts' );
$latest_blog_posts = get_posts( array(
'posts_per_page' => 4,
'post_type' => 'post',
'post_status' => 'publish'
) );
foreach ( $latest_blog_posts as $blog_post ) {
$post_thumbnail_url = get_the_post_thumbnail_url( $blog_post->ID, 'large' );
$post_thumbnail_url_full = get_the_post_thumbnail_url( $blog_post->ID );
$dominant_color = get_post_meta( $blog_post->ID, 'dominant_color', true );
$dominant_color_css = str_replace('[', 'background-color:rgb(', $dominant_color);
$dominant_color_css = str_replace(']', ')', $dominant_color_css);
?>
<div class="col-sm-6 col-md-6 col-lg-3 list-item">
<div class="card w-100">
<a href="<?php echo get_permalink( $blog_post->ID ); ?>">
<div class="overflow-hidden" style="<?php echo $dominant_color_css; ?>">
<img loading="lazy" class="lazy-load card-img-top" src="<?php echo $post_thumbnail_url; ?>" data-src="<?php echo $post_thumbnail_url_full; ?>" alt="<?php echo $blog_post->post_title; ?>">
</div>
</a>
<div class="card-body">
<h5 class="card-title">
<a class="stretched-link" class="stretched-link" href="<?php echo get_permalink( $blog_post->ID ); ?>"><?php echo $blog_post->post_title; ?></a>
</h5>
<p class="card-text"><?php echo $blog_post->post_excerpt; ?></p>
</div>
</div>
</div>
<?php } ?>
</div>
<p><a class="btn" href="/blog/">Visit the blog</a></p>
<!-- /post details -->
</div>
</div>
</div>
</main>
<?php get_footer(); ?>