:::

7-5 完成側邊欄的近期新聞

一、完成側邊欄新聞列表

  1. 修改 index.phpswitch()之後, 用 all() 取得指定數量的新聞的文章,做成 $aside_news 的樣板變數送至樣板檔。
    $smarty->assign('aside_news', all(0, 15));
    $smarty->assign('now_op', $op);
    $smarty->display('index.tpl');

     

  2. 最後編輯 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>

     

  3. 看起來像這樣:

二、讓發布頁面也有側邊欄內容

  1. 修改 admin.php ,一樣在 switch() 之後用 all() 取得指定數量的新聞的文章,做成 $aside_news 的樣板變數送至樣板檔。
  2. 不過 all() 以及其相關函數目前是放在 index.php ,為了讓 admin.php 也能使用,需將之移至 function.php,包括 all()convertMediaToJson()truncate_string()..等含函數,都需移至 function.php

 


:::

書籍目錄

展開 | 闔起

http%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D2029%26tbsn%3D55

計數器

今天: 2815281528152815
昨天: 2259225922592259
總計: 7951613795161379516137951613795161379516137951613