:::
7-2 完成首頁輪播圖及新聞列表
- 編輯
index.php,修改一下switch流程,在沒有$id編號時,就是列出所有新聞switch ($op) { case 'embed': # code... break; default: if (!empty($id)) { $smarty->assign('news', show($id)); $op = "show"; } else { $smarty->assign('all_news', all($start)); $op = "main"; } break; } - 因為有用到新變數
$start,所以,也記得要加入過濾,這次給個預設值5,也就是5篇換一頁<?php require 'header.php'; // 過濾外部傳來變數 $op = filter_input_var('op'); $id = filter_input_var('id', 'int'); $start = filter_input_var('start', 'int', 0); - 開啟
templates/main.tpl,將原本的載入新聞語法改用Smarty迴圈來進行,並且設定第一筆資料要載入輪播圖,其餘的只載入縮圖{foreach $all_news as $key => $news} {if $key==0} {include file="article.tpl" slider=true title=$news.news_title date=$news.report_date school=$news.school_name count=$news.views author=$news.publisher content=$news.news_content link=$news.related_link thumb=""} {else} {include file="article.tpl" slider=false title=$news.news_title date=$news.report_date school=$news.school_name count=$news.views author=$news.publisher content=$news.news_content link=$news.related_link thumb=$news.thumb_image} {/if} {/foreach} - 這樣就大功告成了。

7-1 取得指定的新聞資料數