搜索页

因为时间关系,暂时只列举出一些常用标签
搜索表单
<form method="get" action="{SITE_URL}index.php" target="_blank">
  <div class="input-group">
    <div class="input-group-prepend">
    <select id="searchselected" class="form-control custom-select ">
      <option data="1">文章</option>
      <option data="2">产品</option>
      <option data="3">下载</option>
    </select>
    </div>
    <input type="hidden" name="modelid" value="1" id="modelid" class="modelid-class" />
    <input id="input-searchForm" type="text" name="q" required class="form-control br-tl-7 br-bl-7" placeholder="输入关键词">
    <div class="input-group-append ">
    <button type="submit" class="btn btn-primary br-tr-7 br-br-7">
      搜索
    </button>
    </div>
  </div>
</form>
<script type="text/javascript">
    $(document).ready(function(){
    $(document).on('change','#searchselected',function(){
      var selected = $(this).find("option:selected").attr('data');
     $(".modelid-class").attr('value',selected)
   });
  })
</script>
用我自己的模板来演示,因为毕竟还是用select的比较多。在这里有个重点就是如果选择某个模型进行搜索,要实现搜索模型匹配,通过一段JS来实现,红字标出的地方一定要注意前后一致。
搜索结果页(search.html)
<div class="yzm-title">
  <h2>“{$q}” 的搜索结果,共<span>{$total}</span>条</h2>
</div>

{loop $search_data $v}
{php $v['title'] = preg_replace("/$q/i", "<span style='color:red;'>$q</span>", $v['title']);}
{php $v['description'] = preg_replace("/$q/i", "<span style='color:red;'>$q</span>", $v['description']);}
<div class="yzm-news">
  <a href="{$v[url]}" class="yzm-news-img">
    <img src="{get_thumb($v['thumb'])}" alt="{$v[title]}" title="{$v[title]}" />
  </a>
  <div class="yzm-news-right">
    {if strstr($v['flag'],'1')}<em>顶</em>{/if} <!-- 内容属性 -->
    <a href="{$v[url]}">{title_color($v['title'], $v['color'])}</a>
    <p>{$v[description]}</p>
    <div class="yzm-news-tags">
      {php $aid = $v['id'];}
      {m:get sql="SELECT id,tag FROM yzmcms_tag_content AS a LEFT JOIN yzmcms_tag AS b ON a.tagid=b.id WHERE aid=$aid" limit="5" return="tag_data"}
      {loop $tag_data $val} 
      <a href="{tag_url($val['id'])}" target="_blank" >{$val[tag]}</a>
      {/loop}
    </div>
  </div>
</div>    
{/loop}           

<div id="page">{$pages}</div>