2. 選單製做
原始碼 ```
About
Services
Portfolio
Contact
```
![](https://www.ugm.com.tw/uploads/tad_book3/image/ugm_show/nav_01.jpg)得到語法為 ```
SELECT *
FROM `ugm_show_kind`
WHERE `kind` = 'menuTop' AND `enable` = '1'
```
如果要開新視窗 <a> 屬性為 target='\_blank'
因為選單是每個程式都執行,故我們將之放在 head.php or foot.php
foot.php ```
#撈商品資料
$sql = "SELECT `title`,`url`,`target`
FROM `ugm_show_kind`
WHERE `kind` = 'menuTop' AND `enable` = '1'
order by `sort`
";//die($sql);
$result = $db->query($sql) or redirect_header("", 3000, $db->error."\n".$sql,true);
$rows=array();
while($row = $result->fetch_assoc()){
#過濾資料
$row['title'] = htmlspecialchars($row['title'], ENT_QUOTES);
$row['url'] = htmlspecialchars($row['url'], ENT_QUOTES);
$row['target'] = intval($row['target']);
$rows[] = $row;
}
$smarty->assign("menuTop", $rows);//送至樣板
```
creative/theme.tpl ```
<{foreach from=$menuTop item=row key=k}>
target='_blank'<{/if}> ><{$row.title}>
<{/foreach}>
```
3.