美工兼顧SEO,為企業電子商務營銷助力!
自定義定制模塊
一佰互聯網站制作(www.73406278.buzz) 發布日期 2020-10-12 12:30:20 瀏覽數: 9
一、建立數據庫表
admin目錄下增加后臺錄入功能,可以參考jobs目錄,列表,增加,刪除,修改功能
二、模塊化--增加PHP代碼:
根目錄下首頁index.php,mobile/index.php(單獨手機版)及 admin/edittpl/index.php,admin/edittpl/mobile/index.php(單獨手機版),4個PHP文件都要布置相同的PHP代碼
在以上文件中搜索if($row_c['note_class']=='jobs' )在他上邊加入其它模塊判斷示例:
//自定義模塊示例
if($row_c['note_class']=='我定義模塊類型名(英文)' ){
//lang語言,web站點,$offset,$pageSize分頁參考下邊新聞列表
$query ="select * from 表 where 條件 and lang='$lang' and user='$web' ORDER BY limit $offset,$pageSize";
$rs2=$DB->query($query2);
.................
}
//頁面已經有的招聘模塊代碼參考:
//如果為招聘模塊
if($row_c['note_class']=='jobs' )
{
//---------------分頁組裝-----------------------無需分頁可刪除
$sql3 = "select count(*) from jobs where showIndex=1 and lang='$lang' and user='$web' ";
$rs3 = $db->query($sql3);//執行SQL
$pageSize = 10;//每頁數量
$totalRecord = $db->result($rs3,0,0);//計算出總數
$totalPage = @ceil($totalRecord/$pageSize);//計算出總頁數
$noteid=$row_c['id'];//當前模塊分頁標志組裝
$page_variable_name="page".$noteid;
$page=strFilter($_GET[$page_variable_name]);
$page=verify_id($page);//前面已經定義過了用戶傳入的page當前頁碼
if(!$page)$page = 1;
$offset = ($page-1)*$pageSize;
$pageList = GetPageList($_SERVER['PHP_SELF'],$page_variable_name,$listnum?$listnum:"4",$totalPage,$page);
$pagers="{$langInfo['gong']} $totalRecord {$langInfo['gong1']} $totalPage {$langInfo['gong2']} $page {$langInfo['gong3']}";
if($pageList) $pagers.= " <br><br>$pageList[0] $pageList[1]";
//---------------查詢出所有招聘信息-----------------------
$query2 ="select * from jobs where showIndex=1 and lang='$lang' and user='$web' ORDER BY dtCreate asc limit $offset,$pageSize";
$rs2=$DB->query($query2);
//---------遍歷結果集--------并分配到模塊$produ數組供smarty模版調用
while($row_p=$db->fetch_array($rs2)){
//對字段進行處理
$row_p['dtCreate'] = $row_p['dtCreate'];
$row_p['month'] = date("m",strtotime($row_p['dtCreate']));
$row_p['day'] = date("d",strtotime($row_p['dtCreate']));
$Contentall1=$row_p['Content'];
$row_p['Content'] = cutStr($row_p['Content'],40)."...";
$Contentall=$row_p['Content'];
$row_p['Title'] = mb_substr($row_p['Title'],0,$news_btzs,'utf8')."";
$row_p['year'] = date("Y",strtotime($row_p['dtCreate']));
//所有結果集分配到$produ[]數組
$produ[]=array("fuli"=>$row_p['fuli'],"fee"=>$row_p['fee'],"address"=>$row_p['address'],"nub"=>$row_p['nub'],"edu"=>$row_p['edu'],"jinyan"=>$row_p['jinyan'],"month"=>$row_p['month'] ,"year"=>$row_p['year'] ,"day"=>$row_p['day'] ,"id"=>$row_p['id'],"Title"=>$row_p['Title'],"Content"=>$row_p['Content'],"dtCreate"=>date('Y-m-d',strtotime($row_p['dtCreate'])),"Contentall"=>$Contentall,"Contentall1"=>$Contentall1);
}
}
三、模塊化---自定義模板文件設置
在模板目錄新建html文件,寫法參見job_list.html:
1、遍歷語法參smarty官方section循環{{section name=plist loop=$class[clist].produ}}其中produ即為前面定義的數組
2、$class[clist]是上層遍歷直接使用(表示當前模塊)
//CSS代碼,.note{{$class[clist].id}}
<style>
.note{{$class[clist].id}} .th{background:#f4f4f4;margin-bottom:35px}
.note{{$class[clist].id}} .th td{border:1px solid #ddd;text-align:center;font-size:1.4rem;padding:10px 0;}
.note{{$class[clist].id}} .list{border-bottom:1px dashed #ddd;line-height:40px;}
.note{{$class[clist].id}} .list td{text-align:center;font-size:1.2rem;color:#555}
</style>
//plist當前遍歷取名(自定義)
<table style="margin-bottom:25px;background:none;" class="csstable">
<tr class="th" style=""><td>崗位名稱</td>
<td>工作經驗/學歷/人數</td>
<td>工作地點</td>
<td>薪資</td>
<td>發布時間</td>
</tr>
{{section name=plist loop=$class[clist].produ}}
<tr class="list" >
<td style="font-size:1.4rem">{{$class[clist].produ[plist].Title}}</td>
<td style="font-size:1.4rem;">{{$class[clist].produ[plist].jinyan}}/{{$class[clist].produ[plist].edu}}/{{$class[clist].produ[plist].nub}}</td>
<td style="font-size:1.4rem;">{{$class[clist].produ[plist].address}}</td>
<td style="color:#ff7230;font-size:1.6rem;">{{$class[clist].produ[plist].fee}}</td>
<td style="font-size:1.4rem;">{{$class[clist].produ[plist].dtCreate}}</td>
</tr>
<tr class="" ><td colspan="5" style="text-align:left;padding:10px;border:0 ">{{$class[clist].produ[plist].Contentall1}}</td></tr>
{{/section}}
</table>
<!----分頁代碼插入--->
<div class="pagination" id="J_newsPagination" style="padding-top: 50px;">
<div name="laypage1.3" class="laypage_main laypageskin_default" id="laypage_0">
<div class='page'>
{{$class[clist].pagers}}
</div>
</div>
</div>
四、模塊系統引入你定義的文件
在skin/h5-default模板目錄中打開note_class.html,引入你的模板文件。
增加如下代碼:{{elseif $class[clist].note_class=="你定義模塊類型名(英文)"}}{{include file="你寫的模板文件名.html"}},系統執行到這里會判斷如果模塊為你定義的類型名即執行你上邊創建的的html文件。
五、在skin/h5-default模板目錄中打開system_2.html,搜索點擊模塊-拖拽添加,加入增加模塊的風格選擇示例:
<div class="contents searchdivpad" id=''>
<div class="itembox" note_class="product" pro_ms="1">
<img src="/static/mbimg/product_6.png" style="width:250px">
</div>
</div>
1、note_class="前你你定義的模塊類別取名"
2、pro_ms="1" 如果有多種風格在自定義模板文件中加入判斷
{{if $class[clist]=="1" }}
<!----風格一代碼--->
<style>
.note{{$class[clist].id}} .th{background:#f4f4f4;margin-bottom:35px}
.note{{$class[clist].id}} .th td{border:1px solid #ddd;text-align:center;font-size:1.4rem;padding:10px 0;}
.note{{$class[clist].id}} .list{border-bottom:1px dashed #ddd;line-height:40px;}
.note{{$class[clist].id}} .list td{text-align:center;font-size:1.2rem;color:#555}
</style>
//plist當前遍歷取名(自定義)
<table style="margin-bottom:25px;background:none;" class="csstable">
<tr class="th" style=""><td>崗位名稱</td>
<td>工作經驗/學歷/人數</td>
<td>工作地點</td>
<td>薪資</td>
<td>發布時間</td>
</tr>
{{section name=plist loop=$class[clist].produ}}
<tr class="list" >
<td style="font-size:1.4rem">{{$class[clist].produ[plist].Title}}</td>
<td style="font-size:1.4rem;">{{$class[clist].produ[plist].jinyan}}/{{$class[clist].produ[plist].edu}}/{{$class[clist].produ[plist].nub}}</td>
<td style="font-size:1.4rem;">{{$class[clist].produ[plist].address}}</td>
<td style="color:#ff7230;font-size:1.6rem;">{{$class[clist].produ[plist].fee}}</td>
<td style="font-size:1.4rem;">{{$class[clist].produ[plist].dtCreate}}</td>
</tr>
<tr class="" ><td colspan="5" style="text-align:left;padding:10px;border:0 ">{{$class[clist].produ[plist].Contentall1}}</td></tr>
{{/section}}
</table>
<!----分頁代碼插入--->
<div class="pagination" id="J_newsPagination" style="padding-top: 50px;">
<div name="laypage1.3" class="laypage_main laypageskin_default" id="laypage_0">
<div class='page'>
{{$class[clist].pagers}}
</div>
</div>
</div>
{{elseif $class[clist]=="2" }}
風格二代碼
...............
{{else}}
其它
..............
{{/if}}
六、上邊只是錄入、展現,其它邏輯自行開發。
網站目錄下user用戶目錄,product普通產品定單,vhost網站產品,common下Order.class.php定義類。