-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
executable file
·77 lines (69 loc) · 3.44 KB
/
search.php
File metadata and controls
executable file
·77 lines (69 loc) · 3.44 KB
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
<?php
if (!defined('ABSPATH')) {
exit;
}
get_header();
global $wp_query;
$search_query = get_search_query();
$found_posts = (int) $wp_query->found_posts;
$search_title = sprintf(__('搜索:%s', 'lared'), $search_query);
?>
<main class="main-shell keyword-archive-page mx-auto w-full max-w-[1400px] min-h-[calc(100vh-64px)] border-x border-[#d9d9d9] bg-[#ffffff] pb-[90px] max-[900px]:pb-16">
<section class="listing-head border-b border-[#d9d9d9]">
<div class="listing-head-inner">
<span class="listing-head-accent" aria-hidden="true"></span>
<div class="listing-head-main">
<div class="listing-head-title-row">
<h1 class="listing-head-title"><i class="fa-solid fa-magnifying-glass" aria-hidden="true"></i><?php echo esc_html($search_title); ?></h1>
<p class="listing-head-side-stat"><?php printf(esc_html__('共找到 %d 条结果', 'lared'), $found_posts); ?></p>
</div>
</div>
</div>
</section>
<section class="listing-content">
<?php if (have_posts()) : ?>
<div class="search-result-list">
<?php while (have_posts()) : the_post(); ?>
<?php
$post_id = (int) get_the_ID();
$post_type = get_post_type($post_id);
$post_type_obj = get_post_type_object($post_type);
$post_type_label = ($post_type_obj && isset($post_type_obj->labels->singular_name))
? $post_type_obj->labels->singular_name
: strtoupper((string) $post_type);
$excerpt = get_the_excerpt();
if ('' === trim((string) $excerpt)) {
$excerpt = wp_strip_all_tags((string) get_post_field('post_content', $post_id));
}
?>
<article class="search-result-item">
<a class="search-result-link" href="<?php the_permalink(); ?>">
<div class="search-result-meta">
<span class="search-result-type"><?php echo esc_html($post_type_label); ?></span>
<time datetime="<?php echo esc_attr(get_the_date('c')); ?>"><?php echo esc_html(get_the_date('Y/m/d')); ?></time>
</div>
<h2 class="search-result-title"><?php the_title(); ?></h2>
<p class="search-result-excerpt"><?php echo esc_html(wp_trim_words((string) $excerpt, 36, '...')); ?></p>
</a>
</article>
<?php endwhile; ?>
</div>
<div class="lared-pagination">
<?php
the_posts_pagination([
'mid_size' => 2,
'prev_text' => '← ' . __('上一页', 'lared'),
'next_text' => __('下一页', 'lared') . ' →',
'before_page_number' => '',
'screen_reader_text' => __('搜索结果分页', 'lared'),
]);
?>
</div>
<?php else : ?>
<div class="listing-empty">
<p><?php esc_html_e('没有找到匹配内容,请尝试其他关键词。', 'lared'); ?></p>
</div>
<?php endif; ?>
</section>
</main>
<?php get_footer();