簡體   English   中英

Wordpress搜索欄結果為空白頁

[英]Wordpress Search Bar Result a Blank White Page

我的博客側邊欄 有一個簡單的search form ,只會搜索blogs

<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 (但您可以在存檔上看到Hello World博客)
  2. 搜索其他post_type值 - 結果是一個空白頁面,即使我看不到頁眉或頁腳。 例如:搜索ninja這是一種產品類型

這些是代碼,

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;
?>

搜索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-sidebarblog-post-list是HTML結構。

問我是否想要更多細節。

更新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(); ?>

如果我得到一個合理且描述得很好的答案,我可以為這個答案提供賞金。

Wordpress具有內置功能,可以為您提供搜索表單

 <?php 
    get_search_form();
 ?>

https://developer.wordpress.org/reference/functions/get_search_form/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM