<?php
/**
 * 芋头CMS
 * ============================================================================
 * 版权所有 2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利。
 * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷。
 * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-5-30
 */
if (!defined('ROOT_PATH')) { exit('Access Denied'); }
$pageTitle = '搜索结果';
$keyword = trim($_GET['keyword'] ?? '');
$articleList = $productList = [];
if ($keyword !== '') {
    $kw = '%' . $keyword . '%';
    $articleList = $db->fetchAll("SELECT id, title, create_time, 'article' AS tp FROM {$db->table('article')} WHERE status=1 AND title LIKE ? ORDER BY create_time DESC LIMIT 50", [$kw]);
    $productList = $db->fetchAll("SELECT id, title, create_time, 'product' AS tp FROM {$db->table('product')} WHERE status=1 AND title LIKE ? ORDER BY create_time DESC LIMIT 50", [$kw]);
}
$resultList = array_merge($articleList, $productList);
usort($resultList, function($a,$b){ return intval($b['create_time']) <=> intval($a['create_time']); });
require_once __DIR__ . '/_header.php';
?>
<div class="bannern c" style="background:url(<?php echo $site['template_dir']; ?>static/upload/image/20220801/1659354277651388.jpg) no-repeat center;"></div>
<div class="n_cont c">
  <div class="jz c">
    <div class="ny_nav" id="my_sticky">
      <div class="wjssbt c">搜索结果</div>
      <ul class="wjsndh c"></ul>
      <div class="search_l">
        <form method="get" action="<?php echo getUrl('search'); ?>">
          <input type="hidden" name="m" value="search">
          <input type="text" class="ip" name="keyword" placeholder="请输入关键字" value="<?php echo htmlspecialchars($keyword); ?>">
          <input type="submit" class="btn" value="搜索">
        </form>
      </div>
    </div>
    <div class="ny_zqw ny_zqw_chb">
      <div class="nw_top"><span class="top_tzbt l">搜索结果</span><span class="top_mbx r am-icon-home">您的位置： <a href="<?php echo getUrl('home'); ?>">首页</a> >> <a href="javascript:;">搜索结果</a></span></div>
      <div class="h20"></div>
      <div class="bjbld">
        <ul class="wjzlb">
          <?php if ($resultList): ?>
            <?php foreach ($resultList as $row): ?>
            <li class="c"><a href="<?php echo $row['tp'] === 'product' ? getUrl('product', $row['id']) : getUrl('article', $row['id']); ?>"><span class="wjll l"><span class="wjlbt"><i class="am-icon-angle-right"></i><?php echo htmlspecialchars($row['title']); ?></span><span class="wjlrq"><?php echo !empty($row['create_time']) ? date('Y-m-d', $row['create_time']) : ''; ?></span></span></a></li>
            <?php endforeach; ?>
          <?php else: ?>
            <li class="c"><span class="wjll l"><span class="wjlbt">未找到相关内容</span></span></li>
          <?php endif; ?>
        </ul>
      </div>
    </div>
  </div>
</div>
<?php require_once __DIR__ . '/_footer.php'; ?>
