能帮到别人~还真是有成就感啊,又是百度知道里的问题。
有网友向调用当前内容页面 作者发布的所有文档,这个功能之前写过,但是是用sql调用的。
好,下面教大家怎么自己开发一个标签来调用当前作者的所有文章。
首先将以下函数放到 include/extend.func.php 最下边,这个函数是用来获取静态页面的URL地址的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | function GetOneDocUrl($aid) { global $dsql; include_once(DEDEINC."/channelunit.func.php"); $aid = trim(ereg_replace('[^0-9]','',$aid)); $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); $Url = 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 $Url; } |
然后将以下代码保存为 diary.lib.php 放到include/taglib 目录下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <?php if(!defined('DEDEINC')){ exit("Request Error!"); } function lib_diary(&$ctag,&$refObj) { global $dsql,$envs; $jjmhk="row|1,typeid|0"; FillAttsDefault($ctag->CAttribute->Items,$jjmhk); extract($ctag->CAttribute->Items); $innertext = trim($ctag->GetInnerText()); $ctp = new DedeTagParse(); $ctp->SetNameSpace('field','[',']'); $ctp->LoadSource($innertext); $writer = $ctag->GetAtt('writer'); if($writer=='this') { $writer = isset($refObj->Fields['writer']) ? $refObj->Fields['writer'] : 0; } $query = "select a.id,a.title,a.writer,a.pubdate,a.typeid,b.aid from dede_archives a LEFT JOIN dede_addonarticle b on b.aid=a.id where a.typeid='{$typeid}' and a.writer='{$writer}' order by a.pubdate desc LIMIT 0,$row"; $dsql->SetQuery($query); $dsql->Execute('me',$query); while($rs= $dsql->GetArray('me')) { $rs['pubdate']=GetDateMK($rs['pubdate']); $rs['arcurl']=GetOneDocUrl($rs['id']); $rs['title'] = 0 == $titlelen?$rs['title']:cn_substr($rs['title'], $titlelen); $ctp->LoadSource($innertext); foreach($ctp->CTags as$tagid=>$ctag) { if(!empty($rs[strtolower($ctag->GetName())])) { $ctp->Assign($tagid,$rs[$ctag->GetName()]); } } $revalue.= $ctp->GetResult(); } return $revalue; } |
最后再内容页的模板中调用以下标签,下边的li span 标签 自己修改删除。
1 2 3 4 5 | {dede:diary row='10' typeid='2' writer='this'} <li><a href="[field:arcurl/]">[field:title/]</a><span class="p-l5">([field:pubdate/])</span></li> {/dede:diary} |
==============================分割线============================
标签说明:
row= 调用条数
typeid= 调用栏目ID
writer= 默认 this 无需修改
帮百度知道网友免费开发出来的效果,新建立了一个自定义模型,增加了3个自定义字段。 头像,微信号以及二维码上传。