Sturdy Templates
Our templates are updated regularly so they don't break.
```
二、借head.php的nav\_home()來用
1. index.php ```
#################################
# 選單列表程式
#
#################################
function icon_home() {
global $mysqli, $smarty;
#取得所有記錄
$sql = "select sn,title,url,target,content
from `creative_nav`
where `kind`='icon_home' and `enable`='1'
order by `sort` "; //die($sql);
$result = $mysqli->query($sql) or die(printf("Error: %s
" . $sql, $mysqli->sqlstate));
$rows = array();
while ($row = $result->fetch_assoc()) {
#過濾撈出資料
//Array ( [sn] => 3 [ofsn] => 0 [kind] => nav_home [title] => asdfasdf [sort] => 0 [enable] => 1 [url] => asdfasdf [target] => 0 [col_sn] => 0 [content] => )
$row['sn'] = intval($row['sn']);
//http://www.w3school.com.cn/php/func_string_htmlspecialchars.asp
$row['title'] = htmlspecialchars($row['title'], ENT_QUOTES); // 轉換雙引號和單引號
$row['url'] = htmlspecialchars($row['url'], ENT_QUOTES); // 轉換雙引號和單引號
$row['target'] = intval($row['target']);
$content = json_decode($row['content'], true); //(PHP 5 >= 5.2.0 true=>array
$row['icon'] = htmlspecialchars($content['icon'], ENT_QUOTES); // 轉換雙引號和單引號
$row['summary'] = htmlspecialchars($content['summary'], ENT_QUOTES); // 轉換雙引號和單引號
$rows[] = $row;
}
$smarty->assign("icon_home", $rows);
return;
}
```
2. 執行 icon\_home() ```
icon_home();
/*---- 將變數送至樣版----*/
$smarty->assign("WEB", $WEB);
/*---- 程式結尾-----*/
$smarty->display('theme.html');
```
3. templates/default/tpl/creative\_services.html ```
<{foreach from=$icon_home item=row}>
<{$row.title}>
<{$row.summary}>
<{/foreach}>
```
三、顯示單筆新聞(作業)
1. 程式:news.php
2. 樣板:news.html