在制作dedecms模板的时候经常会使用currentstyle标签高亮当前的栏目,具体代码为:
currentstyle='< li class = "current-menu-item" >< a href = "~typelink~" >< i class = "~typefabefore~ fa" ></ i >< span class = "font-text" >~typename~</ span ></ a ></ li >' |
但是在实际建站操作中经常调用自定义字段,大家会发现在用currentstyle的时候读取不出自定义字段的内容了。这时候,我们就需要对dedecms进行修改,以满足我们的需要。
1、我们打开/include/taglib/channel.lib.php文件,在136行找到:
$row [ 'typelink' ] = GetOneTypeUrlA( $row ); |
2、按照格式规则写入我们需要调用的自定义字段。例如,我们要调用abcd字段名,那么我们就这样写:
$linkOkstr = str_replace ( "~abcd~" , $row [ 'abcd' ], $linkOkstr ); |
示例:
//处理同级栏目中,当前栏目的样式 if ( ( $row [ 'id' ]== $typeid || ( $topid == $row [ 'id' ] && $type == 'top' ) ) && $currentstyle != '' ) { $linkOkstr = $currentstyle ; $row [ 'typelink' ] = GetOneTypeUrlA( $row ); $linkOkstr = str_replace ( "~abcd~" , $row [ 'abcd' ], $linkOkstr ); //这一句就是我们新增的字段名 $linkOkstr = str_replace ( "~rel~" , $row [ 'rel' ], $linkOkstr ); $linkOkstr = str_replace ( "~id~" , $row [ 'id' ], $linkOkstr ); $linkOkstr = str_replace ( "~typelink~" , $row [ 'typelink' ], $linkOkstr ); $linkOkstr = str_replace ( "~typename~" , $row [ 'typename' ], $linkOkstr ); $likeType .= $linkOkstr ; } |
3、现在我们就可以在currentstyle中用~abcd~来调取相应的内容了。