Files
2026-09-23 09:29:09 +08:00

77 lines
2.4 KiB
PHP

<?php
/**
* Search results — product search renders as a WooCommerce-style grid.
*
* @package MING
*/
get_header();
$ming_is_product_search = is_search() && ( 'product' === get_query_var( 'post_type' ) ) && class_exists( 'WooCommerce' );
?>
<main class="section">
<div class="wrap">
<p class="eyebrow">SEARCH</p>
<h2 class="h2">
<?php
/* translators: %s: search query. */
printf( esc_html__( '「%s」的搜尋結果', 'ming' ), esc_html( get_search_query() ) );
?>
</h2>
<?php if ( have_posts() ) : ?>
<?php if ( $ming_is_product_search ) : ?>
<ul class="products columns-4 ming-search-grid">
<?php
while ( have_posts() ) :
the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
?>
</ul>
<?php else : ?>
<div style="max-width:46em;margin-top:2.5rem">
<?php
while ( have_posts() ) :
the_post();
?>
<article <?php post_class(); ?> style="margin-bottom:3rem">
<h3 style="font-family:var(--serif);font-weight:600;font-size:1.3rem;letter-spacing:.1em;color:var(--green-deep)">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h3>
<div class="entry-content"><?php the_excerpt(); ?></div>
</article>
<?php
endwhile;
?>
</div>
<?php endif; ?>
<?php
the_posts_pagination(
array(
'prev_text' => __( '上一頁', 'ming' ),
'next_text' => __( '下一頁', 'ming' ),
)
);
?>
<?php else : ?>
<div class="search-empty">
<p><?php esc_html_e( '找不到相關商品,換個關鍵字試試。', 'ming' ); ?></p>
<form role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>" class="searchbar-form">
<input type="search" name="s" value="<?php echo esc_attr( get_search_query() ); ?>" placeholder="<?php esc_attr_e( '搜尋商品名稱', 'ming' ); ?>">
<input type="hidden" name="post_type" value="product">
<button type="submit" class="btn"><?php esc_html_e( '搜尋', 'ming' ); ?></button>
</form>
<a class="textlink" href="<?php echo esc_attr( ming_shop_url() ); ?>"><?php esc_html_e( '瀏覽全部商品 →', 'ming' ); ?></a>
</div>
<?php endif; ?>
</div>
</main>
<?php
get_footer();