Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress搜索显示空结果的空白页_Php_Wordpress_Search - Fatal编程技术网

Php Wordpress搜索显示空结果的空白页

Php Wordpress搜索显示空结果的空白页,php,wordpress,search,Php,Wordpress,Search,我必须建立一个自定义搜索,根据用户填写的表单将用户发送到不同的搜索结果页面,并且搜索也被设置为搜索自定义帖子类型 当搜索找到结果时,所有内容都正确显示,但当它执行空搜索时,它似乎没有运行content-none.php模板。而不是“抱歉,但没有匹配您的搜索条件。请使用其他关键字重试。”这只是一个带有页眉和页脚的空白页面 例如,您可以转到:并在第二个输入中使用“tx”进行有结果的搜索,然后使用随机值进行无结果的搜索 详情: 基本主题:下划线 框架:Zurb 的基础 使用此代码进行了自定义帖子类

我必须建立一个自定义搜索,根据用户填写的表单将用户发送到不同的搜索结果页面,并且搜索也被设置为搜索自定义帖子类型

当搜索找到结果时,所有内容都正确显示,但当它执行空搜索时,它似乎没有运行content-none.php模板。而不是“抱歉,但没有匹配您的搜索条件。请使用其他关键字重试。”这只是一个带有页眉和页脚的空白页面

例如,您可以转到:并在第二个输入中使用“tx”进行有结果的搜索,然后使用随机值进行无结果的搜索

详情:

  • 基本主题:下划线
  • 框架:Zurb 的基础
使用此代码进行了自定义帖子类型搜索更改

为了自定义搜索结果,我使用了本教程

已编辑search.php以将

<?php
/* Template Name: Search Results */
$search_refer = $_GET["site_section"];
if ($search_refer == 'reseller') { load_template(TEMPLATEPATH . '/reseller-search.php'); }
elseif ($search_refer == 'site-search') { load_template(TEMPLATEPATH . '/dealer-search.php'); }; ?>

我将reseller-search.php和dealer-search.php编辑为

<?php
/**
 * The template for displaying search results pages.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
 *
 * @package Biozyme_Connect
 */

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( esc_html__( 'Search Results for: %s', 'bzconnect' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
            </header><!-- .page-header -->
            <span style="background-color:#f87d20; display:block; padding:4px; color:#ffffff; font-weight:bold; text-transform: uppercase;">*Please note that you will be required to login after clicking the link to receive your discounted rates.</span>
            <table width="100%" class="search-results">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Company</th>
                        <th>State</th>
                        <th>Order</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <?php
                        /* Start the Loop */
                        while ( have_posts() ) : the_post();

                            /**
                             * Run the loop for the search to output the results.
                             * If you want to overload this in a child theme then include a file
                             * called content-search.php and that will be used instead.
                             */
                            get_template_part( 'template-parts/content', 'search-reseller' );

                        endwhile;
                        echo '</tr>
                </tbody>
            </table>';

                        the_posts_navigation();

                    else :

                        get_template_part( 'template-parts/content', 'none' );

                    endif; ?>

        </main><!-- #main -->
    </section><!-- #primary -->

<?php
get_footer();
?>

*请注意,您需要在单击链接后登录才能收到折扣费率。
名称
单位
陈述
命令
content-none.php代码

<?php
/**
 * Template part for displaying a message that posts cannot be found.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package Biozyme_Connect
 */

?>

<section class="no-results not-found">
    <header class="page-header">
        <h1 class="page-title"><?php esc_html_e( 'Nothing Found', 'bzconnect' ); ?></h1>
    </header><!-- .page-header -->

    <div class="page-content">
        <?php
        if ( is_home() && current_user_can( 'publish_posts' ) ) : ?>

            <p><?php printf( wp_kses( __( 'Ready to publish your first post? <a href="%1$s">Get started here</a>.', 'bzconnect' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( admin_url( 'post-new.php' ) ) ); ?></p>

        <?php elseif ( is_search() ) : ?>

            <p><?php esc_html_e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'bzconnect' ); ?></p>
            <?php
                get_search_form();

        else : ?>

            <p><?php esc_html_e( 'It seems we can&rsquo;t find what you&rsquo;re looking for. Perhaps searching can help.', 'bzconnect' ); ?></p>
            <?php
                get_search_form();

        endif; ?>
    </div><!-- .page-content -->
</section><!-- .no-results -->


查看您共享的搜索链接并检查“查看源代码”后,似乎根本没有加载
内容none
模板,因为即使HTML也没有显示在
div.main

我现在可以想到两个可能导致这个问题的原因:

1.检查以确保您确实进入了
else:
状态。虽然这不太可能,但可以肯定这是好事。所以通过做类似的事情来检查它

     else :
                echo 'Nothing found!';
                get_template_part( 'template-parts/content', 'none' );

            endif; ?>
检查是否可以看到
未找到任何内容在页面上

  • 确保content-none.php文件确实存在,即

    a。它位于正确的目录中,例如
    模板部件/content none.php
    ,请确保我们的路径正确

    b。文件名是正确的,例如它不是
    cotent none.php
    content noen.php
    或类似的内容


  • 定义('WP_DEBUG',true);你试过调试吗?谢谢,我以前没用过。我可以看到它在哪里抛出了一个错误,我为一个页面或页面的子页面添加了条件语句<代码>
    我用一个基本的
    结束了它,所以我假设它会默认为这个。好的,这个[链接]为我指出了正确的方向,以删除我收到的对象错误,但它仍然只是显示了一个白色页面。还可以添加来自
    模板部件/content none.php
    文件的代码我简直不敢相信这是什么。content-none.php模板就在那里,但当我仔细看时,我意识到它加载了0 KB的文件大小,所以它没有读取任何内容。谢谢
         else :
                    echo 'Nothing found!';
                    get_template_part( 'template-parts/content', 'none' );
    
                endif; ?>