当您进行空白搜索时,WordPress 搜索会转到帖子页面 [英] WordPress Search goes to post page when you do a blank search

查看:32
本文介绍了当您进行空白搜索时,WordPress 搜索会转到帖子页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,我把我的 wordpress 主题放在一起......

Yea so on my wordpress theme I've put together...

当您单击搜索按钮(搜索字段为空)时,它会将您带到博客页面.我已将 index.php 指定为博客页面并制作了另一个页面并将其指定为主页.

When you click the search button (with the search field empty) it takes you to the blog page. I have assigned the index.php as the blog page and made another page and assigned that as the home page.

有人可以帮忙吗?这不是一个大问题,但这是一个我想摆脱的小故障.

Can anyone help? Its not a major problem but it is a little glitch I would like to get rid of.

谢谢.

特里

推荐答案

我也遇到了同样的问题,wordpress默认给的.

I also faced the same problem, it is default given by wordpress.

但幸运的是我找到了一些对我有帮助的东西.

but luckily I found something which helped me.

在Functions.php"下面添加

Add below in "Functions.php"

 function SearchFilter($query) {
    // If 's' request variable is set but empty
    if (isset($_GET['s']) && empty($_GET['s']) && $query->is_main_query()){
        $query->is_search = true;
        $query->is_home = false;
    }
    return $query;}
add_filter('pre_get_posts','SearchFilter');

然后在search.php中替换下面的行(第15行)

and then replace below line(line no 15) in search.php

<?php if ( have_posts() && strlen( trim(get_search_query()) ) != 0 ) : ?>

也许它也能帮到你

有关详细信息,请阅读:自定义空搜索 wordpress

For details read this : Customize empty search wordpress

这篇关于当您进行空白搜索时,WordPress 搜索会转到帖子页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆