開發範例:顯示最新10則新聞


顯示最新10條新聞程式編寫範例# 程式碼編寫# 存放目錄格式:# #
#
外掛程式存放目錄用: /e/extend/newnews/
外掛程式模板存放目錄用: /e/extend/newnews/template/
# 所需程式檔案:# #
## #
/e/extend/newnews/index.php主程式檔案
/e/extend/newnews/template/index.temp.php主程式模板檔

# #
程式目錄 模板目錄
    主程式檔案內容(/e/extend/newnews/index.php#):
<?php
require('../../class/connect.php'); //引入資料庫設定檔與公用函數檔
require('../../class/db_sql.php'); //引入資料庫操作檔
require('../../data/dbcache/class.php'); //引入欄位快取檔案
$link=db_connect(); //連線MYSQL
# $empire=new mysqlquery(); //宣告資料庫操作類別
$editor=1; //宣告目錄層次

$sql=$empire->query("select * from {$dbtbpre}ecms_news order by newstime limit 10"); //查詢新聞表最新10筆記錄
require('template/index.temp.php'); //導入模板檔

#

db_close(); //關閉MYSQL連結
$empire=null; //取消操作類別變數
?>


主程式模板檔案內容(/e/extend/newnews/template/index.temp.php):
<?php
# if(!defined('InEmpireCMS'))
{
        exit();
}
?>

# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-類型" content="text/html; charset=gb2312">
<title>顯示最新10個新聞範例</title>
</head>
<body>
<br>
<br>
<br>
<table width="500" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
    <td height="25"><strong>顯示最新10則新聞:</strong></td>
  </tr>
  <tr>
    <td height="25" bgcolor="#FFFFFF">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <?php
#                 while($r=$empire->fetch($sql))        //循環取得查詢記錄
                {
                        $titleurl=sys_ReturnBqTitleLink($r);        //標題連結
                ?>
#                 <tr>
                <td width="67%" height="25">·<a href="<?=$titleurl?>" target="_blank">
                <?=esub(stripslashes($r[title]),32)?>
                </a></td>
                <td width="33%"><div align="center">[<?=date('Y-m-d',$r[newstime])?>]</div></td>
                </tr>
                <?php
#                 }
                ?>
#                 </table>

    </td>
  </tr>
</table>
</body>
</html>
說明:模板可用Dreamweaver視覺化製作。其中藍色部分程式碼為不允許直接存取模板檔案的作用。   存取Hello World外掛程式檔案主程式:/e/extend/newnews/index.php# #