:::
7-5 完成側邊欄的近期新聞
一、完成側邊欄新聞列表
- 修改
index.php的switch()之後, 用all()取得指定數量的新聞的文章,做成$aside_news的樣板變數送至樣板檔。$smarty->assign('aside_news', all(0, 15)); $smarty->assign('now_op', $op); $smarty->display('index.tpl'); - 最後編輯
templates/aside.tpl就完成了!<div class="card my-4"> <div class="card-header">近期新聞</div> <ul class="list-group list-group-flush"> {foreach $aside_news as $key => $news} <li class="list-group-item"> {$news.report_date} 【{$news.school_name}】 <div><a href="index.php?id={$news.id}" class="text-decoration-none">{$news.news_title}</a></div> </li> {/foreach} </ul> </div> - 看起來像這樣:

二、讓發布頁面也有側邊欄內容
- 修改
admin.php,一樣在switch()之後用all()取得指定數量的新聞的文章,做成$aside_news的樣板變數送至樣板檔。 - 不過
all()以及其相關函數目前是放在index.php,為了讓admin.php也能使用,需將之移至function.php,包括all()、convertMediaToJson()、truncate_string()..等含函數,都需移至function.php。
7-4 加入文章分頁功能