搜索表单不适用于Wordpress

时间:2014-08-08 11:46:27

标签: wordpress search

我在wordpress上的搜索表单有问题。当我尝试搜索任何一个词时它会给我"抱歉,没有帖子符合您的查询"响应(我已经"搜索所有内容"也安装了插件)。我正在使用儿童主题。所以我试图改变子search.php中的代码(将其复制到子),并在子代中创建了一个searchform.php。以下是我目前使用的两个代码:

的search.php:

> <?php
/**
 * Search Template
 *
 * The search template is used to display search results from the native WordPress search.
 *
 * If no search results are found, the user is assisted in refining their search query in
 * an attempt to produce an appropriate search results set for the user's search query.
 *
 * @package WooFramework
 * @subpackage Template
 */

 get_header();
 global $woo_options;
?>      
    <!-- #content Starts -->
    <?php woo_content_before(); ?>
    <div id="content" class="col-full">

        <div id="main-sidebar-container">    

            <!-- #main Starts -->
            <?php woo_main_before(); ?>
            <section id="main" class="col-left">

                <header class="page-header">
                <h1 class="page-title"><?php printf( __( 'Search Results for: %s', '' ), get_search_query() ); ?></h1>
            </header><!-- .page-header -->
<?php
$query = new WP_Query( array( 's' => get_query_var('s')) );

// The Loop
if ( $query->have_posts() ) {
    echo '<ul>';
    while ( $query->have_posts() ) {
        $query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
} 
?>
<?php var_dump($the_query) ?>
            </section><!-- /#main -->

            <?php get_sidebar(); ?>

        </div><!-- /#main-sidebar-container -->         

        <?php get_sidebar( 'alt' ); ?>       

    </div><!-- /#content -->
    <?php woo_content_after(); ?>
<?php get_footer(); ?>

SEARCHFORM.PHP(我从二十二个主题中得到):

<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
        <label for="s" class="assistive-text"><?php _e( 'Search', 'twentyeleven' ); ?></label>
        <input type="text" class="field" name="s" id="s" placeholder="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
        <input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
    </form>

我也尝试过searchform.php的不同代码,例如:

  <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
        <label class="hidden" for="s"><?php _e('Search:'); ?></label>
        <input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
        <input type="submit" id="searchsubmit" value="GO" />
    </form>

<form role="search" method="get" id="searchform" class="searchform" action="<?php esc_url( home_url( '/' )); ?>">
    <div>
        <label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label>
        <input type="text" value="<?php get_search_query(); ?>" name="s" id="s" />
        <input type="submit" id="searchsubmit" value="<?php esc_attr_x( 'Search', 'submit button' ); ?>" />
    </div>
</form>

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

但仍然没有。当它搜索时,这就是我在网址中得到的结果:

http://www.energyhealing.directory/?s=energy&submit=Search

并在该网址的页面上显示:

搜索结果:能量&lt;&lt;它的标题

列于 继续阅读&lt;&lt;这是一个无处的链接,只是回到同一页

如果有人可以向我解释我哪里出错了,为什么,这会很棒?

提前感谢您提供的任何帮助。我期待着您的回复!

噢好我现在看到如何在问题中发帖:

以下是search.php中的代码,它只返回空白页:

  <?php
/**
 * Search Template
 *
 * The search template is used to display search results from the native WordPress search.
 *
 * If no search results are found, the user is assisted in refining their search query in
 * an attempt to produce an appropriate search results set for the user's search query.
 *
 * @package WooFramework
 * @subpackage Template
 */

 get_header();
 global $woo_options;
?>      
    <!-- #content Starts -->
    <?php woo_content_before(); ?>
    <div id="content" class="col-full">

        <div id="main-sidebar-container">    

            <!-- #main Starts -->
            <?php woo_main_before(); ?>
            <section id="main" class="col-left">

                <header class="page-header">
                <h1 class="page-title"><?php printf( __( 'Search Results for: %s', '' ), get_search_query() ); ?></h1>
            </header><!-- .page-header -->
<?php
$query = new WP_Query( array( 's' => get_query_var('s')) );

// The Loop
if ( $query->have_posts() ) {
    echo '<ul>';
    while ( $query->have_posts() ) {
        $query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
} 
?>
            </section><!-- /#main -->

            <?php get_sidebar(); ?>

        </div><!-- /#main-sidebar-container -->         

        <?php get_sidebar( 'alt' ); ?>       

    </div><!-- /#content -->
    <?php woo_content_after(); ?>
<?php get_footer(); ?>

1 个答案:

答案 0 :(得分:0)

EDITED(对于search.php):

<?php if ( have_posts() ):?> 
        <ul>
        <?php while ( have_posts() ) : the_post();?>

            <li><?php the_title();?></li>
        <?php endwhile;?>
        </ul>
 <?php endif;?>

我认为searchform.php还可以,但我在你的search.php中找不到任何循环

$query = new WP_Query( array( 's' => get_query_var('s')) );


// The Loop
if ( $query->have_posts() ) {
    echo '<ul>';
    while ( $query->have_posts() ) {
        $query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
} 

您需要此查询才能根据搜索创建循环。