织梦DedeCMS多篇文章高亮功能实现教程

在织梦网站建设中,当需要为“关于我们”等多篇文章列表添加当前页面高亮功能时,可以通过修改核心文件并调用自定义参数来实现。以下是详细的操作步骤。

第一步:修改核心文件获取currentstyle属性

打开织梦CMS的核心文件,找到以下代码:

$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'] = "<a href='".$row['filename']."'>".$row['title']."</a>";

在该代码下方插入:

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="<li><a href='~typelink~' class='thisclass'>~typename~</a></li>"}
[field:array runphp='yes']
if(@me['currentstyle']){
@me = @me['currentstyle'];
}else{
@me = "<li><a href='{@me['filename']}'>{@me['title']}</a></li>";
}
[/field:array]
{/dede:arclist}

通过以上步骤,即可在织梦CMS中实现多篇文章列表的当前页面高亮显示功能,提升网站用户体验和导航清晰度。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。