搜索

常用的和不常用的首页标签都会列出,根据用途会有所缺少,欢迎补充。
搜索表单
           <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="m" value="search" />
			  <input type="hidden" name="c" value="index" />
			  <input type="hidden" name="a" value="init" />
			  <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="search_content">      
	<p class="jieguo">“{$q}”的结果,共<span>{$total}</span>条</p>
	{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="sousuo">
	  <b><a href="{$v[url]}" target="_blank">{$v[title]}</a></b>
	  <p><a href="{$v[url]}" target="_blank">{$v[description]}</a></p>
	  <span>[{date("Y-m-d",$v['updatetime'])}]</span>
	  </div>           
	{/loop}         
	<div id="page">{$pages}</div>        
	</div>