#檢查資料表(ugm_p_news) if (!chk_isTable("{$WEB['moduleName']}_news")) { $sql = " CREATE TABLE `{$WEB['moduleName']}_news` ( `sn` int(10) unsigned NOT NULL auto_increment comment 'prod_sn', `kind` smallint(5) unsigned NOT NULL default 0 comment '分類', `title` varchar(255) NOT NULL default '' comment '名稱', `summary` text NULL comment '摘要', `content` text NULL comment '內容', `price` int(10) unsigned NOT NULL comment '價格', `amount` int(10) unsigned NOT NULL comment '數量', `enable` enum('1','0') NOT NULL default '1' comment '狀態', `choice` enum('1','0') NOT NULL default '0' comment '精選', `date` int(10) unsigned NOT NULL default 0 comment '建立日期', `sort` smallint(5) unsigned NOT NULL default 0 comment '排序', `counter` int(10) unsigned NOT NULL default 0 comment '人氣', `icon` varchar(255) NOT NULL default '' comment '圖示', PRIMARY KEY (`sn`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; "; createTable($sql); } ``` ### 二、複製商品管理程式、樣板 1. admin\_prod.php -> admin\_news.php 2. templates/admin/tpl/admin\_prod.tpl -> templates/admin/tpl/admin\_news.tpl 3. 將關鍵字 prod -> news、商品 -> 新聞 ### 三、修改後台主樣板 1. templates/admin/theme.tpl ``` <{* 新聞管理 *}> <{elseif $WEB.file_name == "admin_news.php"}> <{include file="tpl/admin_news.tpl"}> ``` 2. templates/admin/tpl/topBar.tpl ```
<{* 新聞管理 *}> <{elseif $WEB.file_name == "admin_news.php"}> <{include file="tpl/admin_news.tpl"}> ``` 2. templates/admin/tpl/topBar.tpl ```
########################################################### # 撈商品資料 ########################################################### function get_news() { global $db, $smarty; #撈商品資料 $sql = "select a.`sn`,a.`title`,a.`summary`,a.`icon` from `ugm_show_news` as a where a.`enable`='1' order by a.`sort` desc ";//die($sql); $result = $db->query($sql) or redirect_header("", 3000, $db->error."\n".$sql,true); $rows=[]; while($row = $result->fetch_assoc()){ #過濾資料 $row['sn'] = intval($row['sn']); $row['title'] = htmlspecialchars($row['title'], ENT_QUOTES); $row['summary'] = htmlspecialchars($row['summary'], ENT_QUOTES); $row['icon'] = htmlspecialchars($row['icon'], ENT_QUOTES); $rows[] = $row; } //print_r($rows);die(); $smarty->assign("newss", $rows);//送至樣板 } ``` 3. 樣板 templates/creative/theme.tpl ``` <{foreach from=$newss item=row}> <{$row.title}> <{$row.summary}> <{/foreach}> ``` 4.
<{foreach from=$newss item=row}> <{$row.title}> <{$row.summary}> <{/foreach}> ``` 4.
<{$row.summary}>