2016-02-05 125 views
0

我使用裸体新闻主题来构建我的网站,并且除了使用搜索栏之外,它的所有功能都很棒。我输入我的搜索内容,然后将我带到我的主页版本,但没有内容。WordPress搜索结果不显示

如何让我的搜索结果显示?

+0

WordPress搜索表单在您的主题文件夹中调用search.php。这个文件里有什么? – aletede91

回答

0

创建一个search.php并以此代码为例。

<?php get_header(); ?> 
 
<div id="content"> 
 
<?php if (have_posts()) : ?> 
 
\t <h1>Search Result for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' &mdash; '); echo $count . ' '; _e('acapellas'); wp_reset_query(); ?></h1> 
 
\t <ul> 
 
\t <?php while (have_posts()) : the_post(); ?> 
 
\t \t <li> 
 
\t \t \t <h2><?php the_title(); ?></h2> 
 
\t \t \t <p><?php the_excerpt(); ?></p> 
 
\t \t </li> 
 
\t <?php endwhile; endif; ?> 
 
\t </ul> 
 
</div> 
 
<?php get_footer(); ?>

确保您searchform.php与WordPress的标准,下面有一个例子规定。

<form method="get" class="search-form" action="<?php echo home_url('/'); ?>"> 
    <label> 
     <span class="screen-reader-text"><?php echo _x('Search:', 'label') ?></span> 
     <span>Search</span> 
     <input type="search" class="search-field" placeholder="Search" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x('Search:', 'label') ?>" /> 
    </label> 
    <button type="submit" class="search-submit" value="<?php echo esc_attr_x('Search', 'submit button') ?>"> 
    </button> 
</form>