程序代码编写

存放目录格式:

插件程序存放目录用: /e/extend/newnews/

插件程序模板存放目录用: /e/extend/newnews/template/

所需程序文件:

/e/extend/newnews/index.php 主程序文件 /e/extend/newnews/template/index.temp.php 主程序模板文件

程序目录 模板目录

主程序文件内容(/e/extend/newnews/index.php):

  1. <?php
  2. require('../../class/connect.php'); //引入数据库配置文件和公共函数文件
  3. require('../../class/db_sql.php'); //引入数据库操作文件
  4. require('../../data/dbcache/class.php'); //引入栏目缓存文件
  5. $link=db_connect(); //连接MYSQL
  6. $empire=new mysqlquery(); //声明数据库操作类
  7. $editor=1; //声明目录层次
  8. $sql=$empire->query("select * from {$dbtbpre}ecms_news order by newstime limit 10"); //查询新闻表最新10条记录
  9. require('template/index.temp.php'); //导入模板文件
  10. db_close(); //关闭MYSQL链接
  11. $empire=null; //注消操作类变量
  12. ?>

主程序模板文件内容(/e/extend/newnews/template/index.temp.php):

  1. <?php
  2. if(!defined('InEmpireCMS'))
  3. {
  4. exit();
  5. }
  6. ?>
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  5. <title>显示最新10条新闻例子</title>
  6. </head>
  7. <body>
  8. <br>
  9. <br>
  10. <br>
  11. <table width="500" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
  12. <tr>
  13. <td height="25"><strong>显示最新10条新闻:</strong></td>
  14. </tr>
  15. <tr>
  16. <td height="25" bgcolor="#FFFFFF">
  17. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  18. <?php
  19. while($r=$empire->fetch($sql)) //循环获取查询记录
  20. {
  21. $titleurl=sys_ReturnBqTitleLink($r); //标题链接
  22. ?>
  23. <tr>
  24. <td width="67%" height="25">·<a href="<?=$titleurl?>" target="_blank">
  25. <?=esub(stripslashes($r[title]),32)?>
  26. </a></td>
  27. <td width="33%"><div align="center">[<?=date('Y-m-d',$r[newstime])?>]</div></td>
  28. </tr>
  29. <?php
  30. }
  31. ?>
  32. </table>
  33. </td>
  34. </tr>
  35. </table>
  36. </body>
  37. </html>

说明:模板可用Dreamweaver可视化制作。其中蓝色部分代码为不允许直接访问模板文件的作用。

访问Hello World插件文件主程序:/e/extend/newnews/index.php