0

我在我的 Bootstrap 3 站点中添加了一个搜索框,但如果尝试搜索它不会拉出任何结果的内容,它只会刷新您所在的页面:

看到这个

<form class="navbar-form" role="search">
  <div class="form-group">
    <input type="text" class="form-control" placeholder="Search">
  </div>
  <button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
</form>

我以为是因为我没有 search.php 文件,但是添加后我仍然遇到同样的问题。

搜索.php

<?php
/**
 * The template for displaying Search Results pages
 *
 * @package WordPress
 * @subpackage Wp_Bootstrap
 * @since Wp Bootstrap 1.0
 */

get_header(); ?>

    <div id="primary" class="content-area">
        <div id="content" class="site-content" role="main">

        <?php if ( have_posts() ) : ?>

            <header class="page-header">
                <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'wpbootstrap' ), get_search_query() ); ?></h1>
            </header>

            <?php /* The loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>
                <?php get_template_part( 'content', get_post_format() ); ?>
            <?php endwhile; ?>

            <?php wpbootstrap_paging_nav(); ?>

        <?php else : ?>
            <?php get_template_part( 'content', 'none' ); ?>
        <?php endif; ?>

        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
4

3 回答 3

1

您的表单<form class="navbar-form" role="search">标签不包含操作,您需要为输入文本命名

<form class="navbar-form" role="search" action="<?php esc_url( site_url() ) ?>" method="get">
    <div class="form-group">
       <input name="s" type="text" class="form-control" placeholder="Search">
    </div>
       <button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
</form>
于 2014-01-02T09:05:06.897 回答
1

此代码可能对您有用

<form class="navbar-form navbar-right" role="search" action="search.php" method="get">
<div class="form-group">
<input type="text" name="s" value="<?php $_GET['s']; ?>" class="form-control" placeholder="search...">
</div>
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-search"></span></button>
</form>

理解

在参数操作中,您需要放置文件search.php的路径

输入类型上,您需要添加参数名称,这是您用于搜索的参数,即s

接下来你需要添加 value 参数并添加这个<?php $_GET['s']; ?>

您已完成,测试此代码并判断它是否适合您。

试试这个更新的代码

<form class="navbar-form navbar-right" role="search" action="<?php bloginfo('url'); ?>/" method="get">
    <div class="form-group">
    <input type="text" name="s" value="<?php $_GET['s']; ?>" class="form-control" placeholder="<?php _e('Search', 'wpbootstrap'); ?>">
    </div>
    <button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-search"></span></button>
    </form>
于 2014-01-06T01:55:46.560 回答
0

我在这里分享个人经验。

请注意,我在这里分享的代码还没有为您的主题准备好,因为您应该 [至少] 将 textdomain 从

minimax3

your_text_domain

如果您像这样设置搜索表单,则搜索表单可以工作:

<form class="navbar-form navbar-right" role="search" action="<?php bloginfo('url'); ?>/" method="get">
        <div class="form-group">
            <input name="s" type="text" class="form-control" placeholder="<?php _e('Search', 'minimax3'); ?>">
        </div>
        <button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
</form>

请注意,不需要添加 value 参数,因为这样

<?php $_GET['s']; ?>

请注意,我的主题的根文件夹中有一个 search.php,如下所示:

<?php get_header(); ?>
<div class="container">
<div class="row">
    <div id="primary" class="col-lg-9 col-md-9">
        <div id="content" class="site-content" role="main">

            <?php if ( have_posts() ) : ?>

                <header class="page-header">
                    <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'minimax3' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
                </header><!-- .page-header -->

                <?php minimax3_content_nav( 'nav-above' ); ?>

                <!--Start the Loop-->
                <?php while ( have_posts() ) : the_post(); ?>

                    <?php get_template_part( 'content', 'search' ); ?>

                <?php endwhile; ?>

                <?php minimax3_content_nav( 'nav-below' ); ?>

                <br>

                <!--Inlcude the search form at the bottom-->
                <div class="container">
                    <div class="row">
                        <div id="primary" class="col-lg-9 col-md-9">
                            <h3><?php _e( 'Not what you were looking for?', 'minimax3' ); ?></h3>
                            <p><?php _e( 'Refine your search below!', 'minimax3' ); ?></p>
                            <?php get_search_form(); ?>
                        </div>
                    </div>
                </div>

                <!--If no results-->
                <?php else : ?>

                <?php get_template_part( 'no-results', 'search' ); ?>

            <?php endif; ?>

        </div><!-- #content .site-content -->
</section><!-- #primary .content-area -->

<?php get_footer(); ?>

如果您仍然得到“白页”(WPOD),您可能需要在您的 wp-config.php 中打开 WP Debug Constante,如下所示:

define( 'WP_DEBUG', true );

然后告诉我们您将在屏幕上看到的错误,这会有所帮助;)

于 2015-04-25T00:28:24.690 回答