Emlog之TangStyle模板修改首页导航为树状显示
继修改了的侧边栏模板后,修改首页导航便变得轻车熟路了,现在我带大家一起来学习Emlog之TangStyle模板修改首页导航为树状显示,先看一下效果图。
下面来讲讲方法,我们还是打开module.php,找到以下源代码:
<?php function blog_navi(){ global $CACHE; $navi_cache = $CACHE->readCache('navi'); ?> <ul id="nav"> <?php foreach($navi_cache as $value): if($value['type'] == 3 && (ROLE == 'admin' || ROLE == 'writer')): ?> <li><a href="<?php echo BLOG_URL; ?>admin/write_log.php">写日志</a></li> <li><a href="<?php echo BLOG_URL; ?>admin/">管理站点</a></li> <li><a href="<?php echo BLOG_URL; ?>admin/?action=logout">退出</a></li> <?php continue; endif; $newtab = $value['newtab'] == 'y' ? 'target="_blank"' : ''; $value['url'] = $value['isdefault'] == 'y' ? BLOG_URL . $value['url'] : trim($value['url'], '/'); $current_tab = (BLOG_URL . trim(Dispatcher::setPath(), '/') == $value['url']) ? 'current' : 'common'; ?> <li class="<?php echo $current_tab;?>"><a href="<?php echo $value['url']; ?>" <?php echo $newtab;?>><?php echo $value['naviname']; ?></a></li> <?php endforeach; ?> </ul> <?php }?>替换为:
<?php //blog:导航 function blog_navi(){ global $CACHE; $navi_cache = $CACHE->readCache('navi'); ?> <ul class="bar"> <?php foreach($navi_cache as $value): if($value['url'] == ROLE_ADMIN && (ROLE == ROLE_ADMIN || ROLE == ROLE_WRITER)): ?> <li class="item common"><a href="<?php echo BLOG_URL; ?>admin/write_log.php">写文章</a></li> <li class="item common"><a href="<?php echo BLOG_URL; ?>admin/">管理站点</a></li> <li class="item common"><a href="<?php echo BLOG_URL; ?>admin/?action=logout">退出</a></li> <?php continue; endif; $newtab = $value['newtab'] == 'y' ? 'target="_blank"' : ''; $value['url'] = $value['isdefault'] == 'y' ? BLOG_URL . $value['url'] : trim($value['url'], '/'); $current_tab = BLOG_URL . trim(Dispatcher::setPath(), '/') == $value['url'] ? 'current' : 'common'; ?> <li class="item <?php echo $current_tab;?>"> <a href="<?php echo $value['url']; ?>" <?php echo $newtab;?>><?php echo $value['naviname']; ?></a> <?php if (!empty($value['children'])) :?> <ul class="sub-nav"> <?php foreach ($value['children'] as $row){ echo '<li><a href="'.Url::sort($row['sid']).'">'.$row['sortname'].'</a></li>'; }?> </ul> <?php endif;?> </li> <?php endforeach; ?> </ul> <?php }?>这段代码是从Emlog的默认模板中提取出来的,在手机站上会显得有限怪异,下面我们继续来修改: