【发布时间】:2018-10-10 15:23:15
【问题描述】:
我正在使用自定义构建的主题,但在构建搜索页面时遇到了问题。
主题基于 HTML Bones 项目 - https://github.com/eddiemachado-zz/bones
我已经设法让搜索页面显示循环,但它没有使用提供的搜索词,而是显示所有产品。
我希望有更多经验的人能够指出为什么在此设置中忽略了搜索词?
搜索表单的代码是:
<form role="search" method="get" id="searchform" class="searchform" action="<?php echo site_url( '/' ); ?>">
<div>
<label for="s" class="screen-reader-text"><?php _e('Search for:','bonestheme'); ?></label>
<input type="search" id="s" name="s" value="" />
<button type="submit" id="searchsubmit" ><?php _e('Search','bonestheme'); ?></button>
</div>
</form>
结果页面代码为:
<?php
/**
* The template for displaying search results pages.
*
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="container site-main" role="main">
<ul id="product-list-global" class="products product-list-global col-sm-9">
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 12
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
?>
</ul><!--/.products-->
<?php
get_template_part( 'sidebar-shop-default' ); ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();
感谢阅读!
【问题讨论】:
标签: php wordpress loops search woocommerce