<?php //无限分类用ul,li.good!!! 使用前,在此调用此函数的地方前面加<div class="nav">,后面加</div>。 function show_subcategory($category_id){ static $nums=0; $nums++; $sql = mysql_query("select * from newsclass where fatherid ='$category_id'"); if(mysql_num_rows($sql)>0){ if ($nums==1) { echo '<ul id=nav>'; }else{ echo '<ul>'; } while($rs = mysql_fetch_array($sql)){ if ($rs['fatherid']==0){ echo '<li>' ."<a href=class.php?id={$rs['id']}>". $rs['classname']."</a>"; }else{ echo '<li>' ."<a href=class.php?id={$rs['id']}>". $rs['classname']."</a>"; } echo show_subcategory(($rs['id'])); echo '</li>'; } echo '</ul>'; } } //调用:show_subcategory(0);
还要在下面加入以下css
/* 导航 */
.nav {
clear:both;
width:994px;
height:44px;
margin:0px auto;
padding:0px auto;
color:white;
background:url(images/nav_bg.png) left top no-repeat;
}
#nav {padding-left:20px;}
#nav li {float: left;text-align:left;}
#nav a { color:white;text-decoration: none;}
#nav li.one {
float:left;
width:96px;
height:44px;
line-height:40px;
text-align:center;
font-size:14px;
overflow:hidden;
}
#nav li.one a {
display:block;
width:96px;
height:44px;
background:url(images/nav_line.gif) right top no-repeat;
}
#nav li.on {
background:url(images/nav_on.gif) left top repeat-x;
font-weight:bold;
}
#nav li.one:hover,#nav li.one a:hover {
width:96px;
color:#104578;
font-weight:bold;
background:url(images/nav_hover.gif) left 3px no-repeat;
}
#nav li.one:hover a,#nav li.one ul li a:hover {color:#104578;background:none;}
.ifocus {z-index:99; position: relative;}
#nav li ul {position: absolute;left: -999em;height: auto;width: 208px;margin:0px 0px 0px -3px;_margin:0px 0px 0px -47px; padding:0px 0px 10px 0px; background:url(images/nav_a_bg.png) left bottom no-repeat;z-index:99999; }
#nav li ul li {display: block; width:208px;height:28px;line-height:28px;overflow:hidden;}
#nav li ul ul {margin: -2.8em 0 0 14em;}
#nav li ul span,#nav li ul ul span {display:block; margin:0px 5px; border-top:2px solid #DADADA;}
#nav li:hover ul ul, #nav li:hover ul ul ul, #nav li.sfhover ul ul, #nav li.sfhover ul ul ul {left: -999em;}
#nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li.sfhover ul, #nav li li.sfhover ul, #nav li li li.sfhover ul {left: auto;}
#nav li.one ul li a,#nav li.one ul li a:link {width:158px; margin-left:40px;color:#333;font-weight:normal;font-size:12px;background:none;}
#nav li.one ul li a:hover {color:#104578;}
最后更新于 2022年7月8日