我创建了自己的搜索表单页面和搜索页面,但知道当我搜索某些内容时,搜索结果没有提供任何内容,我在网上搜索了很多内容并按照一些教程找到问题,但我不能。她是代码:
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 :(得分: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(); ?>