2016-02-05 138 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>