在Dedecms CMS系统中,`artlist`标签有时需要实现当前文章高亮显示,或者与`channelartlist`标签结合使用以实现当前栏目和当前文章的高亮效果。本文将详细介绍如何通过修改核心文件来实现这一功能。 首先,我们来实现`artlist`标签的当前文章高亮效果。 ### 修改步骤 1. **打开核心文件** 打开 `include/taglib/arclist.lib.php` 文件。 2. **添加代码** 在以下代码行后增加新代码: ```php $channelid = $ctag->GetAtt('channelid'); ``` 增加: ```php $currentstyle = $ctag->GetAtt('currentstyle'); ``` 3. **继续修改参数列表** 在 `$tagid,$pagesize,$isweight` 后面增加: `, $currentstyle` 4. **定义默认值** 在 `$noflag='',$tagid='', $pagesize=0, $isweight='N'` 后面增加: `, $currentstyle=''` 5. **添加高亮逻辑** 在以下代码行后面增加: ```php $row['textlink'] = "".$row['title'].""; ``` 增加: ```php 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}
    --- 接下来,如果需要与 `channelartlist` 标签结合使用,可以按照以下步骤操作: ### 修改 `channelartlist` 标签 1. **打开文件** 打开 `include/taglib/channelartlist.lib.php` 文件。 2. **定位并插入代码** 找到以下代码行: ```php $pv->Fields['typeurl'] = GetOneTypeUrlA($typeids[$i]); ``` 在此行代码下方插入以下代码: ```php if($typeids[$i]['id'] == $refObj->TypeLink->TypeInfos['id'] || $typeids[$i]['id'] == $refObj->TypeLink->TypeInfos['topid']){ $pv->Fields['currentstyle'] = $currentstyle ? $currentstyle : 'current'; } else{ $pv->Fields['currentstyle'] = ''; } ``` 3. **注意** 网上大部分教程未包含 `$typeids[$i]['id'] == $refObj->TypeLink->TypeInfos['topid']` 这部分代码。添加该部分后,二级栏目的高亮功能才能正常工作。 ### 调用示例
    
    {dede:channelartlist typeid='2' currentstyle='current'}
    
  • {dede:field name='typename'/}
  • {/dede:channelartlist}
    如果是当前栏目,则 `
  • ` 的 `class` 属性会显示为 `current`;否则,`class` 属性为空。您也可以自定义 `currentstyle` 参数以设置其他类名。 --- ### 完整调用示例 以下是完整的调用代码示例,结合了 `channelartlist` 和 `arclist` 标签:
    
    {dede:channelartlist typeid='2' currentstyle='current'}
    
    
    {dede:field name='typename'/}
    {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} {/dede:channelartlist}
    通过以上步骤,您可以轻松实现 Dedecms 中当前文章或栏目的高亮显示功能。希望这篇文章对您有所帮助!