下面教大家怎么自己开发一个织梦标签来调用当前作者的所有文章。
首先将以下函数放到 include/extend.func.php 最下边,这个函数是用来获取静态页面的URL地址的。
01 |
function GetOneDocUrl($aid) |
04 |
include_once(DEDEINC. "/channelunit.func.php" ); |
05 |
$aid = trim(ereg_replace( '[^0-9]' , '' ,$aid)); |
07 |
$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' " ); |
09 |
if (!is_array($chRow)) { |
13 |
if (empty($chRow[ 'maintable' ])) $chRow[ 'maintable' ] = 'dede_archives' ; |
16 |
if ($chRow[ 'issystem' ]!=-1) |
18 |
$nquery = " Select arc.*,tp.typedir,tp.topid,tp.namerule,tp.moresite,tp.siteurl,tp.sitepath |
19 |
From `{$chRow[ 'maintable' ]}` arc left join `dede_arctype` tp on tp. id =arc.typeid |
20 |
where arc. id = '$aid' "; |
24 |
$nquery = " Select arc.*,1 as ismake,0 as money, '' as filename,tp.typedir,tp.topid,tp.namerule,tp.moresite,tp.siteurl,tp.sitepath |
25 |
From `{$chRow[ 'addtable' ]}` arc left join `dede_arctype` tp on tp. id =arc.typeid |
26 |
where arc.aid= '$aid' "; |
29 |
$arcRow = $dsql->GetOne($nquery); |
31 |
$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' ]); |
|
然后将以下代码保存为 diary.lib.php 放到include/taglib 目录下
04 |
* @version $Id: diary.lib.php 1:37 2015年6月2日 by 织梦58 |
05 |
* @link http://www.dede58.com |
07 |
if (!defined( 'DEDEINC' )){ |
08 |
exit ( "Request Error!" ); |
10 |
function lib_diary(&$ctag,&$refObj) |
13 |
$jjmhk= "row|1,typeid|0" ; |
14 |
FillAttsDefault($ctag->CAttribute->Items,$jjmhk); |
15 |
extract($ctag->CAttribute->Items); |
16 |
$innertext = trim($ctag->GetInnerText()); |
17 |
$ctp = new DedeTagParse(); |
18 |
$ctp->SetNameSpace( 'field' , '[' , ']' ); |
19 |
$ctp->LoadSource($innertext); |
20 |
$writer = $ctag->GetAtt( 'writer' ); |
23 |
$writer = isset($refObj->Fields[ 'writer' ]) ? $refObj->Fields[ 'writer' ] : 0; |
25 |
$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" ; |
26 |
$dsql->SetQuery($query); |
27 |
$dsql->Execute( 'me' ,$query); |
28 |
while ($rs= $dsql->GetArray( 'me' )) |
30 |
$rs[ 'pubdate' ]=GetDateMK($rs[ 'pubdate' ]); |
31 |
$rs[ 'arcurl' ]=GetOneDocUrl($rs[ 'id' ]); |
32 |
$rs[ 'title' ] = 0 == $titlelen?$rs[ 'title' ]:cn_substr($rs[ 'title' ], $titlelen); |
34 |
$ctp->LoadSource($innertext); |
35 |
foreach($ctp->CTags as$tagid=>$ctag) { |
36 |
if (!empty($rs[strtolower($ctag->GetName())])) { |
37 |
$ctp->Assign($tagid,$rs[$ctag->GetName()]); |
40 |
$revalue.= $ctp->GetResult(); |
|
最后再内容页的模板中调用以下标签,下边的li span 标签 自己修改删除。
{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 无需修改