2017-01-27 114 views
2

我正在创建一个WP主题。我的搜索功能无法正常工作。 当我点击搜索按钮时,什么也没有发生,它甚至不会刷新页面。但是当我输入URL www.example.com/?s=Lorem时,我得到了结果。我不明白为什么我的搜索按钮不起作用。谁能告诉我如何解决这个问题?下面你将看到我的search.php和searchform.phpWordPress搜索不起作用

的search.php

<?php get_header(); ?> 
    <main role="main"> 
     <!-- section --> 
     <section> 

      <h1><?php echo sprintf(__('%s search-form Search Results for ', 'mytheme'), $wp_query->found_posts); echo get_search_query(); ?></h1> 

      <?php get_template_part('loop'); ?> 
     </section> 
     <!-- /section --> 
    </main> 
<?php get_footer(); ?> 

searchform.php

<div id="search"> 
    <button type="button" class="close" style="background:transparent;border-radius: 0px;">x</button> 
    <form method="get" id="searchform" action="<?php echo esc_url(home_url('/')); ?>"> 
     <input type="search" value="" name="s" placeholder="<?php if (!empty($theme_options['search_placeholder'])) { echo $theme_options['search_placeholder']; } ?>" /> 
     <button type="submit" class="btn btn-primary"><?php _e('Search', 'mytheme'); ?></button> 
    </form> 
</div> 
+0

此代码对我的作品与twentysixteen主题,但占位自然显示为空。当你var_dump($ theme_options)会发生什么? –

回答

0

可能是你错过的东西。用以下代码替换输入标签代码

<input type="search" 
    value="<?php the_search_query(); ?>" 
    name="s" 
    placeholder="<?php if(!empty($theme_options['search_placeholder'])) { 
     echo $theme_options['search_placeholder']; 
    } ?>" 
/> 
0

谢谢您的回答。 我最初的代码上面是工作的罚款,我从我的的functions.php去除

wp_register_script('slick.min', get_template_directory_uri() . '/js/slick.min.js', array('jquery'), '1.0.0', true); 
     //wp_enqueue_script('slick.min'); // Enqueue it!