在Dedecms中,要实现文章高亮功能,需要对代码进行适当的修改。以下是具体步骤:
// 第一步:在以下代码后插入
$channelid = $ctag->GetAtt('channelid');
// 插入以下代码
$currentstyle = $ctag->GetAtt('currentstyle');
接下来,查找以下代码:
return lib_arclistDone(
$refObj, $ctag, $typeid, $ctag->GetAtt('row'), $ctag->GetAtt('col'), $titlelen, $infolen,
$ctag->GetAtt('imgwidth'), $ctag->GetAtt('imgheight'), $listtype, $orderby,
$ctag->GetAtt('keyword'), $innertext, $envs['aid'], $ctag->GetAtt('idlist'), $channelid,
$ctag->GetAtt('limit'), $flag, $ctag->GetAtt('orderway'), $ctag->GetAtt('subday'), $ctag->GetAtt('noflag'),
$tagid, $pagesize, $isweight
);
将其替换为:
return lib_arclistDone(
$refObj, $ctag, $typeid, $ctag->GetAtt('row'), $ctag->GetAtt('col'), $titlelen, $infolen,
$ctag->GetAtt('imgwidth'), $ctag->GetAtt('imgheight'), $listtype, $orderby,
$ctag->GetAtt('keyword'), $innertext, $envs['aid'], $ctag->GetAtt('idlist'), $channelid,
$ctag->GetAtt('limit'), $flag, $ctag->GetAtt('orderway'), $ctag->GetAtt('subday'), $ctag->GetAtt('noflag'),
$tagid, $pagesize, $isweight, $currentstyle
);
这一步的关键在于在函数调用中添加了一个 `$currentstyle` 实参。
继续查找以下代码:
function lib_arclistDone(&$refObj, &$ctag, $typeid=0, $row=10, $col=1, $titlelen=30, $infolen=160,
$imgwidth=120, $imgheight=90, $listtype='all', $orderby='default', $keyword='',
$innertext='', $arcid=0, $idlist='', $channelid=0, $limit='', $att='', $order='desc', $subday=0, $noflag='', $tagid='', $pagesize=0, $isweight='N')
将其替换为:
function lib_arclistDone(&$refObj, &$ctag, $typeid=0, $row=10, $col=1, $titlelen=30, $infolen=160,
$imgwidth=120, $imgheight=90, $listtype='all', $orderby='default', $keyword='',
$innertext='', $arcid=0, $idlist='', $channelid=0, $limit='', $att='', $order='desc', $subday=0, $noflag='', $tagid='', $pagesize=0, $isweight='N', $currentstyle='')
这里的主要改动是在函数定义中添加了 `$currentstyle=''` 形参。
最后,查找以下代码:
$row['textlink'] = "".$row['title']."";
在其下方插入以下代码:
if($currentstyle && $row['id']==$arcid){
$currentstyle = str_replace('~typelink~', $row['filename'], $currentstyle);
$row['currentstyle'] = str_replace('~typename~', $row['title'], $currentstyle);
}
保存文件后,即可完成代码修改。
调用方法如下:
{dede:arclist titlelen='42' row='10' currentstyle="~typename~"}
[field:array runphp='yes']
if(@me['currentstyle']){
@me = @me['currentstyle'];
}else{
@me = "{@me['title']}";
}
[/field:array]
{/dede:arclist}