个性化阅读
专注于IT技术分析

WordPress搜索栏结果空白页

我的博客侧边栏上有一个简单的搜索表单, 该表单仅搜索博客。

<form action="<?php echo get_site_url() ?>" method="GET">
   <input type="search" name="s" placeholder="Click to Search" class="fld-search" required/>
   <input type="hidden" name="post_type" value="post">
   <button class="btn-search"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>

这是网站网址:http://dev.wonder.lk/blog/

以下是我应用的搜索类型,

  1. 博客中可用的值-对于某些值, 它可以提供结果, 但有时它表示未找到。范例:搜寻你好(但你可以在档案库中看到Hello World网志)
  2. 搜索其他post_type值-结果是白页, 即使我看不到页眉或页脚。例如:搜索忍者这是产品类型

这些是代码,

search.php

<?php
while ( have_posts() ) : the_post();
   if(isset($_GET['post_type'])) {
           $type = $_GET['post_type'];
           if($type == 'product') {
              get_template_part( 'woocommerce/archive', 'product' ); //working fine
           } else {
              get_template_part( 'framework/template-parts/page/search', 'post' );
           }
   } else {
           get_template_part( 'framework/template-parts/page/search', 'post' );
   }
   endwhile;
?>

search-post.php

<?php

get_header();

//Page Title Bar
$pageTitle = 'Search results for: "'.get_search_query().'"';
echo page_title_bar( $pageTitle, get_template_directory_uri().'/framework/assets/images/pg-title-bar.jpg');
?>

<div class="container blog-wrapper page-container">
    <div class="row">
        <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

                <?php
                    // Include Blog Posts List
                    get_template_part('framework/template-parts/post/blog', 'post-list');
                ?>

            <?php endwhile; ?>

            <div class="pagination-wrapper">
                <?php pagination(); ?>
            </div>

            <?php else: ?>
                <h3>No results found for: '<?php echo get_search_query(); ?>'</h3>
            <?php endif; ?>
        </div>

        <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
            <?php
                // Include Blog Sidebar
                get_template_part('framework/template-parts/post/blog', 'sidebar');
            ?>
        </div>
    </div>
</div>


<?php get_footer(); ?>

blog-sidebar和blog-post-list是HTML结构。

问我是否需要更多详细信息。


#1


如下更新search.php后, 它工作正常,

<?php

get_header();

//Page Title Bar
$pageTitle = 'Search results for: "'.get_search_query().'"';
echo page_title_bar( $pageTitle, get_template_directory_uri().'/framework/assets/images/pg-title-bar.jpg');
?>

<div class="container blog-wrapper page-container">
    <div class="row">
        <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

                <?php
                    // Include Blog Posts List
                    get_template_part('framework/template-parts/post/blog', 'post-list');
                ?>

            <?php endwhile; ?>

            <div class="pagination-wrapper">
                <?php pagination(); ?>
            </div>

            <?php else: ?>
                <h3>No results found for: '<?php echo get_search_query(); ?>'</h3>
            <?php endif; ?>
        </div>

        <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
            <?php
                // Include Blog Sidebar
                get_template_part('framework/template-parts/post/blog', 'sidebar');
            ?>
        </div>
    </div>
</div>


<?php get_footer(); ?>

如果我得到一个合理且描述清楚的答案, 我可以为该答案提供赏金。


#2


WordPress具有内置功能, 可为你提供搜索表单

 <?php 
    get_search_form();
 ?>

get_search_form()

赞(0)
未经允许不得转载:srcmini » WordPress搜索栏结果空白页

评论 抢沙发

评论前必须登录!