織夢dedecms 使用artlist標簽顯示當前文章高亮
2024-07-12 08:56:10
供稿:網友
 
                        在織夢系統中的artlist有時候需要當前文章高亮,或者和channelartlist標簽套用實現當前欄目高亮和當前文章高亮,就可以通過此方法實現:
首先實現artlist當前文章高亮:
打開include/taglib/arclist.lib.php
在
$channelid = $ctag->GetAtt('channelid');
下增加:
$channelid = $ctag->GetAtt('channelid');
在
$tagid,$pagesize,$isweight 后增加  ,$currentstyle
在$noflag='',$tagid='', $pagesize=0, $isweight='N' 后增加 ,$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 class='current' ><a href='~typelink~'>~typename~</a></li>"}
     [field:array runphp='yes']
         if(@me['currentstyle']){
             @me = @me['currentstyle'];
         }else{
             @me = "<li class='abc' ><a href='{@me['arcurl']}'>{@me['title']}</a></li>";
         }
     [/field:array]
{/dede:arclist}
如果和channelartlist搭配使用,方法如下:
打開include/taglib/channelartlist.lib.php
找到
$pv->Fields['typeurl'] = GetOneTypeUrlA($typeids[$i]);
在此行代碼下方增加以下代碼:
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'] = '';
        }
網上找到的一般沒有加$typeids[$i]['id'] ==$refObj->TypeLink->TypeInfos['topid'] 
添加這個后才能對二級欄目也起作用
調用方法:
{dede:channelartlist typeid='2' currentstyle='current'}
<li class='{dede:field.currentstyle/}'><a href='{dede:field name='typeurl'/}'>{dede:field name='typename'/}</a></li>
。。。
{/dede:channelartlist}
如果是當前欄目則 li的class屬性顯示current,否則顯示class='' ,也可以修改currentstyle='這里改為你需要的類名'。
這樣調用:
{dede:channelartlist typeid='2' currentstyle='current'}
<dt ><a class='{dede:field.currentstyle/}' href='{dede:fieldname='typeurl'/}'>{dede:field name='typename'/}</a></dt>
{dede:arclist titlelen='42' row='10' currentstyle="<dd><a class='current' href='~typelink~'>~typename~</a></dd>"}
     [field:array runphp='yes']
         if(@me['currentstyle']){
             @me = @me['currentstyle'];
         }else{
             @me = "<dd ><a href='{@me['arcurl']}'>{@me['title']}</a></dd>";
         }
     [/field:array]
{/dede:arclist}
{/dede:channelartlist}