一、原本前台 theme.html 的語法
套件是放在「{literal}」裡面,所以應該無法放變數進來,所以把這段移回去程式裡面,再從程式用變數傳至樣板
二、著手套用修改
#定義常用變數 $TBL['name']="show_kind";//資料表名稱 $TBL['kind']="slider_home";//分類
流程控制
//預設動作 default: $op="op_list"; op_list(); break;
######################################## # 列表 ######################################## function op_list() { global $mysqli,$smarty,$TBL; #取得所有記錄 $sql = "select * from `{$TBL['name']}` where `kind`='{$TBL['kind']}' order by `sort` ";//die($sql); $result = $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate)); $rows=array(); while($row = $result->fetch_assoc()) { #過濾撈出資料 $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['sort'] = intval($row['sort']); $row['enable'] = $row['enable'] ? "是":"<span style='color:red;'>否</span>"; $row['target'] = $row['target'] ? "是":"<span style='color:red;'>否</span>"; #取得圖片src $col_name = "slider_home"; $row['file_name'] = get_file_name_src($row['sn'],$col_name); $rows[]= $row; } $smarty->assign("DBV", $rows); return; }
#函數 ######################################## # 列表 ######################################## function op_list() { global $mysqli,$smarty,$TBL; #取得所有記錄 $sql = "select * from `{$TBL['name']}` where `kind`='{$TBL['kind']}' and `enable`='1' order by `sort` ";//die($sql); $result = $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate)); /* $backstretch_js=" <script type='text/javascript'> $(document).ready(function(){ $('.top-content').backstretch([ 'http://fakeimg.pl/1600x1200/ff0000/' , 'http://fakeimg.pl/1600x1200/00ff00/' , 'http://fakeimg.pl/1600x1200/0000ff/' ], {duration: 3000, fade: 750}); }); </script> "; */ $file_name=""; $col_name = "slider_home"; while($row = $result->fetch_assoc()) { #過濾撈出資料 $row['sn'] = intval($row['sn']); $comma = $file_name ? ", ":""; #取得圖片src $file_name .= $comma. "'" .get_file_name_src($row['sn'],$col_name). "'"; } $backstretch_js=""; if($file_name){ $backstretch_js=" <script type='text/javascript'> \$(document).ready(function(){ \$('.top-content').backstretch([ {$file_name} ], {duration: 3000, fade: 750}); }); </script> "; } $smarty->assign("backstretch_js", $backstretch_js); return; }
{$backstretch_js}