Closed zachb3123 closed 3 months ago
@zachb3123,感谢你给 sakurairo 提出了 issue。ヾ(≧▽≦*)o 请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。
看到以前提交过一个建议#786,和这个类似。但我还是无法理解,请在此问题下详细描述你的想法和建议,我们可以讨论一下。
简单来说那就是不用搜索页面板块,只搜文章标题和文章的内容就行。页面直接点击就行, 如果有很多的用户使用页面,可以加入搜索搜索筛选
本来页面就不会有标签的,只有文章有标签,所以会有未分类显示
这也有可能主题的显示的原因, 因为点击主题每一个页面、文章、标签都是以同一方式显示的.
下面是我简单修改一下:
①例如把这些加入 functions.php 文件:
// Modify search query to exclude exact page name results
function exclude_page_from_search($query) {
if (!is_admin() && $query->is_search) {
$query->set('post_type', 'post'); // Only search posts
}
return $query;
}
add_filter('pre_get_posts','exclude_page_from_search');
②又或者修改search.php显示方式:
<?php
/**
* The template for displaying search results pages.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
*
* @package Akina
*/
get_header(); ?>
<section id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if (have_posts()) : ?>
<header class="page-header">
<h1 class="page-title"><?php printf(__('Search Results for: %s', 'sakurairo'), '<span>' . get_search_query() . '</span>'); ?></h1>
</header><!-- .page-header -->
<?php
/* Start the Loop */
while (have_posts()) : the_post();
// Exclude pages from search results
if ('page' === get_post_type()) {
continue;
}
// Include template part for posts
get_template_part('tpl/content', get_post_format());
endwhile;
the_posts_navigation();
else : ?>
<div class="search-box">
<!-- search start -->
<form class="s-search">
<input class="text-input" type="search" name="s" placeholder="<?php _e('Search...', 'sakurairo') ?>" required>
</form>
<!-- search end -->
</div>
<?php
get_template_part('tpl/content', 'none');
endif; ?>
<style>
.nav-previous,
.nav-next {
padding: 20px 0;
text-align: center;
margin: 40px 0 80px;
display: inline-block;
font-family: 'Fira Code', 'Noto Sans SC';
}
.nav-previous,
.nav-next a {
padding: 13px 35px;
border: 1px solid #D6D6D6;
border-radius: 50px;
color: #ADADAD;
}
.nav-previous,
.nav-next span {
color: #989898;
font-size: 15px;
}
.nav-previous,
.nav-next a:hover {
border: 1px solid #A0DAD0;
color: #A0DAD0;
}
</style>
</main><!-- #main -->
</section><!-- #primary -->
<?php
get_footer();
简单来说那就是不用搜索页面板块,只搜文章标题和文章的内容就行。页面直接点击就行, 如果有很多的用户使用页面,可以加入搜索搜索筛选
可以提交pr至preview分支@zachb3123
现有内容的优化 / 新增功能 / UI 界面 / 用户体验:
每当搜索到文章的标签分类很正常,如果用户搜索到页面标题会导致“未分类”的出现。在搜索网站内容的时候能不能不搜索页面的标题名字的结果?
请看下面的图片: 例子1
例子2