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

织梦cms在datalist标签中怎么调出文章url

郭俊立2023-12-04DedeCMS教程已有人查阅

导读用过dedecms系统的都知道它的模板标签自由度有很大的局限性,在我使用datalist这个标签时,如果不加扩展是无法直接调用文章的url的地址的。

用过dedecms系统的都知道它的模板标签自由度有很大的局限性,在我使用datalist这个标签时,如果不加扩展是无法直接调用文章的url的地址的。在arclist标签中可用[field:arcurl]调出文章url,在sql标签中
[field:id runphp='yes']$arcRow=GetOneArchive(@me);@me=$arcRow['arcurl'];[/field:id]
也可以调出来。在datalist中似乎没有什么好办法,那只有在程序上扩展了。我们注意到sql标签调用时GetOneArchive函数,看看它如何工作的
打开include文件夹下common.func.php文件找到GetOneArchive函数
//获取单篇文档信息
function GetOneArchive($aid)
{
 global $dsql;
 include_once(DEDEINC."/channelunit.func.php");
 $aid = trim(ereg_replace('[^0-9]','',$aid));
 $reArr = array();
 
 $chRow = $dsql->GetOne("Select arc.*,ch.maintable,ch.addtable,ch.issystem From `dede_arctiny` arc
 
left join `dede_channeltype` ch on ch.id=arc.channel where arc.id='$aid' ");
 
 if(!is_array($chRow)) {
  return $reArr;
 }
 else {
  if(empty($chRow['maintable'])) $chRow['maintable'] = 'dede_archives';
 }
 
 if($chRow['issystem']!=-1)
 {
  $nquery = " Select arc.*,tp.typedir,tp.topid,tp.namerule,tp.moresite,tp.siteurl,tp.sitepath
              From `{$chRow['maintable']}` arc left join `dede_arctype` tp on tp.id=arc.typeid
              where arc.id='$aid' ";
 }
 else
 {
  $nquery = " Select arc.*,1 as ismake,0 as money,'' as filename,tp.typedir,tp.topid,tp.namerule,
 
tp.moresite,tp.siteurl,tp.sitepath
    From `{$chRow['addtable']}` arc left join `dede_arctype` tp on tp.id=arc.typeid
              where arc.aid='$aid' ";
 }
 
 $arcRow = $dsql->GetOne($nquery);
 
 if(!is_array($arcRow)) {
  return $reArr;
 }
 
 if(!isset($arcRow['description'])) {
  $arcRow['description'] = '';
 }
 
 if(empty($arcRow['description']) && isset($arcRow['body'])) {
  $arcRow['description'] = cn_substr(html2text($arcRow['body']),250);
 }
 
 if(!isset($arcRow['pubdate'])) {
  $arcRow['pubdate'] = $arcRow['senddate'];
 }
 if(!isset($arcRow['notpost'])) {
  $arcRow['notpost'] = 0;
 }
$reArr = $arcRow;
$reArr['aid']    = $aid;
$reArr['topid']  = $arcRow['topid'];
$reArr['arctitle'] = $arcRow['title'];
$reArr['arcurl'] = GetFileUrl($aid,$arcRow['typeid'],$arcRow['senddate'],$reArr['title'],$arcRow['ismake'],
$arcRow['arcrank'],$arcRow['namerule'],
$arcRow['typedir'],$arcRow['money'],$arcRow['filename'],$arcRow['moresite'],$arcRow['siteurl'],$arcRow['sitepath']);
return $reArr;
}
不用细究它的细节,我们看到它处理$aid返回了一个$reArr数组,这个数组有arcurl这个元素,这下很好理解sql标签中调用arcurl的方法了。
我们现在扩展一下GetOneArchive函数打开include文件夹下extend.func.php,加入以下代码
function getOneArchiveElement($aid,$element='arcurl'){
$arcRow=GetOneArchive($aid);
return $arcRow[$element];
}
在前台datalist标签中调用:
{dede:field.aid function="GetOneArchiveElement(@me,'arcurl')"}
@me是传递参数aid的功能
这下就解决了datalist标签中调用arcurl的问题,而且GetOneArchiveElement这个函数还能调用其他元素。

本文标签:织梦cms标签 

很赞哦! ()

相关源码

  • (自适应)互联网建站网络公司个人工作室网站模板基于PbootCMS内核开发,围绕「技术方案展示」「成功案例库」「服务流程说明」三大模块构建,支持PC与移动端数据实时同步。附带包含客户评价、行业解决方案的完整测试数据包查看源码
  • (自适应响应式)APP应用程序软件介绍落地页源码免费下载该模板为营销技术从业者设计,提供专业的内容展示平台。采用响应式布局,适配软件介绍、APP推广等营销场景,通过可视化后台可快速搭建符合行业特性的展示网站。查看源码
  • 帝国cms7.5自适应作文新闻资讯教育网站模板本模板基于帝国CMS7.5内核开发,为教育机构、培训学校等知识传播单位打造。通过自适应设计确保在手机、平板、电脑等设备上均能获得专业浏览体验查看源码
  • pbootcms模板(PC+WAP)火锅加盟餐饮美食类带留言源码基于PbootCMS内核深度开发,为火锅、餐饮品牌打造的营销型解决方案。采用红色主题传递行业活力,实现PC与WAP端适配。查看源码
  • (自适应)品牌策划高端设计公司网站pbootcms模板免费下载本模板为品牌策划与设计公司打造,基于PbootCMS内核开发,充分考虑了创意设计行业的视觉展示需求。模板设计风格现代简约,布局合理清晰,呈现设计作品与专业服务,帮助设计公司展示创意实力并吸引潜在客户。查看源码
  • (自适应)蓝色建材亚克力板材装饰材料pbootcms网站模板这款基于PbootCMS开发的响应式模板为建材板材行业优化设计,适用于亚克力板材、建筑装饰材料等企业展示需求。采用HTML5技术实现手机/PC跨终端适配,管理员通过统一后台即可同步查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐