2013-11-20 150 views
0

我做了我自己的搜索表單頁面和搜索頁面,但知道當我搜索的東西搜索結果沒有給我什麼我搜索了很多在網絡上,並遵循一些教程找到問題但我不能。她是代碼:WordPress的搜索頁面不給搜索結果

searchform.php:

<form role="search" method="get" class="visible-lg search-form arrow_box search-back navbar-form navbar-right" action="<?php echo home_url('/'); ?>"> 
    <div class="form-group"> 
     <input type="search" class="search-field form-control" size="49" placeholder="بگەڕێ" value="" name="s" title="بگەڕێ" /> 
    </div> 
    <input type="submit" class="search-submit search-button btn btn-default" value="بگەڕێ" /> 
</form> 

的search.php:

<?php 
/* 
Template Name: Search Page 
*/ 
?> 
<?php get_header(); ?> 
<div class="container"> 
    <div class="row"> 
     <div class="col-md-5 news"> 
      <?php if (have_posts()) : ?> 
       <?php 
       global $wp_query; 
       $total_results = $wp_query->found_posts; 
       ?> 
       <?php printf(__('ئەنجامەکانی گەڕان بۆ: %s', 'shape'), '<span>' . get_search_query() . '</span>'); ?> 
       <?php /* Start the Loop */ ?> 
       <?php while (have_posts()) : the_post(); ?> 
        <?php get_template_part('content', 'search'); ?> 
       <?php endwhile; ?> 
      <?php else : ?> 
       <?php get_template_part('no-results', 'search'); ?> 
      <?php endif; ?> 
     </div> 
     <?php get_sidebar(); ?> 
    </div> 
</div> 
<?php get_footer(); ?> 

回答

0

之後,我嘗試了很多代碼,我終於發現,我必須添加標題或之後的內容while循環,我不知道爲什麼,但這是我剛剛更改了search.php的解決方案:

<?php 
/* 
Template Name: Search Page 
*/ 
?> 
<?php get_header(); ?> 
<div class="container"> 
    <div class="row"> 
     <div class="col-md-5 news"> 
      <?php if (have_posts()) : ?> 
       <?php 
       global $wp_query; 
       $total_results = $wp_query->found_posts; 
       ?> 
       <?php printf(__('serch results for: %s', 'shape'), '<span>' . get_search_query() . '</span>'); ?> 
       <br/><br/> 
       <?php /* Start the Loop */ ?> 
       <?php while (have_posts()) : the_post(); ?> 
        <h4 class=""><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4> 
        <div class="naskh"><?php the_excerpt(); ?></div> 
       <?php endwhile; ?> 
      <?php else : ?> 
       <h4>Nothing found try something else.</h4> 
      <?php endif; ?> 
     </div> 
     <?php get_sidebar(); ?> 
    </div> 
</div> 
<?php get_footer(); ?>