不少站长都喜欢给导航添加样式,站长给出2种方法给Akcms导航当前栏目添加样式
第一种方法:栏目ID读取css样式
栏目读取标签:
<{getcategories rootcategory=$categoryup template="<li><a id=()cate[categoryid]() href=()[url]()>[category]</a></li>"}>
对应的css样式:
<style type="text/css">
#cate<{$category}> {color:#0099cc;font-weight:bold;}
</style>
update 2013-04-23 王磊提示:
以上代码,如果是二级栏目时,会失效,样式代码替换为:
<style type="text/css">
<{if $categoryup eq 0 }>
.cate<{$category}> {background:#1D548B}
<{else}>
.cate<{$categoryup}> {background:#1D548B}
<{/if}>
</style>
第二种方法,用js把当前栏目的样式替换掉。
比如把<li id"nav3">栏目1</li> 的样式替换为 <li id"activepage">栏目1</li>
<script type="text/javascript">
var nav = document.getElementById("nav<{getcategories childcategory=$category num="1" template="[categoryid]"}>");
if (nav) {nav.className = "activepage"};
</script>
栏目读取标签:
<{getcategories num="10" rootcategory="0" template="<li id=()nav[categoryid]()><span><a href=()[url]() ><span>[category]</span></a></span></li>"}>
父栏目首页时,二级栏目标题不需要样式,可以用AK新加入的IF语句:
<{if $subcategories}>
<{getcategories rootcategory=$category template="<li id=()cate[categoryid]()><a href=()[url]()>[category]</a></li>"}>
<{else}>
<style type="text/css">
#cate<{$category}> {
color:#0099cc;
font-weight:bold;
}
</style>
<{getcategories rootcategory=$categoryup template="<li id=()cate[categoryid]()><a href=()[url]()>[category]</a></li>"}>
<{/if}>
转载请注明:本文《Akcms导航给当前栏目添加样式的2种方法》链接: http://seo.leidu.net/post-387.html
百度已收录
发表评论: