首页>帮助>开发手册>开发范例>2、显示最新10条新闻
开发手册
数据字典
模板干扰
体育站群
体育模板
新手帮助

需要支持?

如果通过文档没办法解决您的问题,请提交工单获取我们的支持!

2、显示最新10条新闻

二次开发范例:显示最新10条新闻
显示最新10条新闻程序编写例子
程序代码编写
存放目录格式:
插件程序存放目录用: /e/extend/newnews/
插件程序模板存放目录用: /e/extend/newnews/template/
所需程序文件:
/e/extend/newnews/index.php 主程序文件
/e/extend/newnews/template/index.temp.php 主程序模板文件
程序目录 模板目录
20260110162936499 20260110162936210
主程序文件内容(/e/extend/newnews/index.php):
<?php
require('../../class/connect.php'); //引入数据库配置文件和公共函数文件
require('../../data/dbcache/class.php'); //引入栏目缓存文件
$link=db_connect(); //连接数据库
$empire=new mysqlquery(); //声明数据库操作类
$editor=1; //声明目录层次$sql=$empire->query("select * from {$dbtbpre}ecms_news order by newstime desc limit 10"); //查询新闻表最新10条记录
require('template/index.temp.php'); //导入模板文件

db_close(); //关闭数据库链接
$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-Type" content="text/html; charset=utf-8">
<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可视化制作。其中蓝色部分代码为不允许直接访问模板文件的作用。

访问“显示最新10条新闻”插件文件主程序:/e/extend/newnews/index.php
20260110162936475
上一篇:
1、显示“Hello,world”
下一篇:
3、分类信息分页列表
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
站长

(工作日 10:00 - 22:30 为您服务)

2026-05-08 12:20:27

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

猜你想问:

  • 购买的模板免费包安装吗?

  • 这个演示地址有吗?

  • 购买vip会员可以下载哪些模板?

您的留言我们已经收到,我们将会尽快跟您联系!
取消
立即选择任一渠道联系我们