您现在的位置是:首页 > cms教程 > DedeCMS教程DedeCMS教程

教你制作织梦自定义公告模板

春翠2024-06-08DedeCMS教程已有人查阅

导读比喻站点的较新公告显示位就没有,在网上找了好久,没有发现相关的信息,可能是我没有找到,所以就花了几个小时研究了一下DEDECMS的部分源码,试想,何不自已写呢

比喻站点的较新公告显示位就没有,在网上找了好久,没有发现相关的信息,可能是我没有找到,所以就花了几个小时研究了一下DEDECMS的部分源码,试想,何不自已写呢
好吧,想法有了,开始形动吧,跟我来,让狼人教你DIY一个自定义的模块.
在这里我就给大家举一个实例<<站点公告信息的模板>>
主要有:<<首页显示较新公告>>,<<公告详细显示页面>>,<<公告列表页面>>
好的,我们一个个的来
一.<<首页显示较新公告>>首先是在首页显示较新公告<在index.htm页面添加代码>
{dede:mynews row='1' titlelen='20'}较新公告:[field:title /]<a href="show-mynews.php?aid=[field:aid /]">查看详细</a></div>{/dede:mynews}
end;
二.<<公告详细显示页面>>新建文件show-mynews.php
<?php
require_once (dirname(__FILE__) . "/include/common.inc.php");
require_once DEDEINC."/arc.partview.class.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>公告详细</title>
<link href="/templets/style/dedecms.css" rel="stylesheet" media="screen" type="text/css" />
<script language="javascript" type="text/javascript" src="/include/dedeajax2.js"></script>
<script src="/js/jquery-1.2.6.min.js" language="javascript" type="text/javascript"></script>
</head>
<body>
<?php
$pv = new PartView();
$pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/default/head.htm");
$pv->Display();
?>
<?php
if (! is_numeric($aid))
{
echo "浏览页面参数不正确";
exit;
}
global $dsql;
$row = $dsql->GetOne("Select * from dede_mynews where aid=$aid");
if(!is_array($row))
{
echo "对不起,没有找到您所查找到的公告信息";
exit;
}
?>
<div class="w960 center" style="border:#ccc 1px solid;margin-top:5px;">
<?php
echo "<h1 style='text-align:center;margin-top:20px;font-size:20px;border-bottom:#ccc 1px solid;'>".$row["title"]."</h1>";
echo "<div style='padding:8px;'>".$row["body"]."</div>";
?>
</div>
<?php
$pv = new PartView();
$pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/default/footer.htm");
$pv->Display();
?>
</body>
</html>
三.<<公告列表页面>>改显示所有公告列表,不分页<公告本来就不是很多所以这里我们不分页显示列表了>在include\taglib目录下面找到文件(mynews.lib.php)
代码标签是:------------------------------------------------------------------------------
<?php
function lib_mynews(&$ctag,&$refObj)
{
global $dsql,$envs;
//属性处理
$attlist="row|1,titlelen|24";
FillAttsDefault($ctag->CAttribute->Items,$attlist);
extract($ctag->CAttribute->Items, EXTR_SKIP);
$innertext = trim($ctag->GetInnerText());
if(empty($row)) $row=1;
if(empty($titlelen)) $titlelen=30;
if(empty($innertext)) $innertext = GetSysTemplets('mynews.htm');
$idsql = '';
if($envs['typeid'] > 0) $idsql = " where typeid='".GetTopid($this->TypeID)."' ";
$dsql->SetQuery("Select * from dede_mynews $idsql order by senddate desc limit 0,$row");
if($row == -1) $dsql->SetQuery("Select * from dede_mynews $idsql order by senddate desc");//狼人(QQ:459094521)加,如果设置为-1,就显示所有文章
$dsql->Execute();
$ctp = new DedeTagParse();
$ctp->SetNameSpace('field','[',']');
$ctp->LoadSource($innertext);
$revalue = '';
while($row = $dsql->GetArray())
{
foreach($ctp->CTags as $tagid=>$ctag){
@$ctp->Assign($tagid,$row[$ctag->GetName()]);
}
$revalue .= $ctp->GetResult();
}
return $revalue;
}
?>
在站点根目录新建list-mynews.php里面写代码:
begin:/*用于调用/default/list-mynews.htm页面的标签来显示*/
<?php
require_once (dirname(__FILE__) . "/include/common.inc.php");
require_once DEDEINC."/arc.partview.class.php";
$pv = new PartView();
$pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/default/list-mynews.htm");
$pv->Display();
?>
在templets\default目录下面新建文件list-mynews.htm,并写代码如下:
{dede:mynews row='-1' titlelen='20'}<br/>
编号:[field:aid /],<a href='show-mynews.php?aid=[field:aid /]'>标题:[field:title /]</a>,作者:[field:writer /],发布时间:[field:senddate /],内容:[field:body /]<br/>
{/dede:mynews}
end;

本文标签:

很赞哦! ()

相关源码

  • 自适应新闻资讯技术博客个人网站pbootcms模板该模板基于PbootCMS开源内核深度开发,该模板适用于游戏新闻网站、游戏博客等企业或个人网站,新闻资讯技术博客pbootcms模板;采用六级分辨率断点适配技术查看源码
  • (自适应)简繁双语机械矿山矿石五金设备pbootcms源码下载本模板基于PbootCMS开发,主要面向机械五金、矿山矿石设备等行业,支持简体中文和繁体中文双语切换。采用响应式布局技术,确保在各种设备上都能获得良好的浏览体验。模板设计注重展示工业设备的专业性和技术特点,帮助企业建立可靠的线上展示平台。查看源码
  • (自适应响应式)蓝色律师事务所法务团队网站pbootcms模板为律师事务所和法律服务机构打造的专业网站模板,展现法律专业性与权威性,手工编写标准DIV+CSS代码,结构清晰优化,确保高效运行,自动适配电脑、平板和手机等各类设备,提供更好浏览体验查看源码
  • 帝国cms7.5淘宝客电商品牌特价带手机站带会员模板下载为电商品牌特价展示设计的帝国CMS模板,集成PC端与移动端双平台适配。采用瀑布流商品布局,支持品牌分类聚合展示,突出特价促销视觉冲击力。查看源码
  • (PC+WAP)红色驾校培训学车在线预约源码下载基于PbootCMS内核开发的驾校培训专用网站模板,深度适配驾驶培训行业展示需求。采用PC与移动端同步响应设计,单一后台统一管理内容数据,更换图文素材后可快速转变为其他行业网站。查看源码
  • (自适应响应式)化妆美容口红唇膏化妆品模板pbootcms源码下载基于PbootCMS开发的响应式模板,为化妆品品牌、美容机构打造,通过优雅的视觉呈现提升产品展示效果与品牌调性。采用时尚杂志排版风格,色卡系统规范产品展示。微交互动画增强用户体验,智能推荐算法提升产品关联展示效果。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐