搜索页

因为时间关系,暂时只列举出一些常用标签

YzmCMS V5.8版本新增全站搜索,即表单modelid的值可以等于0

搜索表单
<form method="get" action="{U('search/index/init')}" target="_blank">
    <div id="searchtxt" class="searchtxt">
        <div class="searchmenu">    
            <div class="searchselected" id="searchselected">全站</div>    
            <div class="searchtab" id="searchtab">
                <ul>
                    <li data="0">全站</li>
                    <li data="1">文章</li>
                    <li data="2">产品</li>
                    <li data="3">下载</li>
                </ul>
            </div>
        </div>
        <input type="hidden" name="modelid" value="0" id="modelid" />
        <input name="q" type="text" placeholder="输入关键字"/>
    </div>
    <div class="searchbtn">
        <button id="searchbtn" type="submit">搜索</button>
    </div>
</form>
页面中记得引入公共JS文件
<script type="text/javascript" src="{STATIC_URL}js/yzm-front.js"></script>
在YzmCMS V5.8之前版本,是不支持全站搜索的,所以表单的模型默认 modelid=1,使用前请注意系统版本。
搜索结果页(search.html)
<div class="yzm-title">
    <h2>“{$q}” 的搜索结果,共<span>{$total}</span>条</h2>
</div>

{loop $search_data $v}
{php $v['color_title'] = str_ireplace($q, "<span style='color:red;'>$q</span>", $v['title']);}
{php $v['description'] = str_ireplace($q, "<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]}">{$v[color_title]}</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>