J5_09搜索
需要在可以被搜索的模塊目錄中手動(dòng)添加common/search.jtbc引導(dǎo)文件來(lái)激活搜索功能
需要手動(dòng)構(gòu)建關(guān)鍵字輸入框并通過(guò)get的方式提交到/search/?keyword=關(guān)鍵字
默認(rèn)情況下搜索title字段,如有不同需求需要自行手動(dòng)修改源碼實(shí)現(xiàn)
<form role="search" action="/search/" method="get">
div class="simple-search input-group">
<input class="form-control text-1" id="headerSearch" name="keyword" type="search" value="" placeholder="Search...">
<button class="btn" type="submit" aria-label="Search">
<i class="fas fa-search header-nav-top-icon"></i>
</button>
</div>
</form>
注意name="keyword"要加進(jìn)去的
search.jtbc文件代碼
<?xml version="1.0" encoding="utf-8"?>
<xml mode="jtbc" author="jetiben">
<configure>
<node>item</node>
<field>name,zh-cn</field>
<base>item_list</base>
</configure>
<item_list>
<item>
<name><![CDATA[mode]]></name>
<zh-cn><![CDATA[1]]></zh-cn>
</item>
</item_list>
</xml>
~~~~~~~~~~~~~~~~~~~~~~~~~~
按鈕案例參考
<form role="search" action="/search/" method="get">
<input type="search" name="keyword" class="c-keywords keyword_v1 lf" maxlength="20" placeholder="請(qǐng)輸入關(guān)鍵詞" />
<button id="searchSubmit" class="search-button" title="搜索" aria-label="搜索"></button>
</form>
搜索按鈕css樣式
.search_box_v1 .search-button {
display: inline-block;
width: 30px;
height: 24px;
padding: 0;
border: 0;
position: absolute;
z-index: 10;
right: 0;
top: 20px;
background: url(../images/spirit.png) no-repeat -31px 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~
搜索列表前端模板代碼
<ul class="simple-post-list m-0">
{@}
<li>
<div class="post-info">
<i class="fas fa-angle-right"></i><a href="{$linkurl}">{$title}</a>
</div>
</li>
{@}
</ul>
搜索列表css樣式
/* Simple Post List */
ul.simple-post-list {
list-style: none;
margin: 0;
padding: 0;
}
ul.simple-post-list li {
border-bottom: 1px dotted #E2E2E2;
padding: 15px 0;
}
ul.simple-post-list li::after {
clear: both;
content: "";
display: block;
}
ul.simple-post-list li:last-child {
border-bottom: 0;
}
ul.simple-post-list li a{color:#5d5e60}
ul.simple-post-list li a:hover{color:#0ec5a1}
ul.simple-post-list .post-image {
float: left;
margin-right: 12px;
}
ul.simple-post-list .post-meta {
color: var(--grey-900);
font-size: 0.8em;
}
ul.simple-post-list .post-info {
line-height: 20px;
}
@media (max-width: 575px) {
ul.comments li {
border-left: 8px solid rgba(0, 0, 0, 0.06);
clear: both;
padding: 0 0 0 10px;
}
ul.comments li .img-thumbnail {
display: none;
}
ul.comments .comment-arrow {
display: none;
}
}
/* Simple Post List end */