二级导航

燃烧的冰2019-12-28  239

wellcms 2.0 页头调用导航和子菜单的方式,直接复制使用。


第一种下拉菜单:

<ul class="navbar-nav mr-auto">
   <li class="nav-item home" fid="0" data-active="fid-0">
      <a class="nav-link" href="<?php echo $conf['path'] ;?>"><i class="icon-home d-md-none"></i>&nbsp;<?php echo lang('index_page');?></a>
   </li>
   <!-- 遍历需要显示的导航 -->
   <?php if ($forum_nav = category_tree($forum_nav)) { foreach($forum_nav as $_forum) { ?>
   <!-- li 格式 重新定义或添加新 class -->
   <li class="nav-item <?php if ($_forum['son']){echo 'dropdown';}?>" fid="<?php echo $_forum['fid'];?>" data-active="fid-<?php echo $_forum['fid'];?>">
      <!-- a标签格式 重新定义或添加新 class -->
      <a class="nav-link <?php if ($_forum['son']){echo 'dropdown-toggle';}?>" href="<?php echo $_forum['url'];?>" <?php if ($_forum['son']){echo 'id="Menu-'.$_forum['fid'].'" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"';}?> <?php if ($_forum['category'] == 3){echo 'target="_blank"';}?>>
         <i class="icon-circle-o d-md-none"></i>&nbsp;<?php echo $_forum['name'];?>
      </a>
      <!--子菜单-->
      <?php if ($_forum['son']){ ?>
      <div class="dropdown-menu" aria-labelledby="Menu-<?php echo $_forum['fid'];?>">
         <?php foreach($_forum['sonlist'] as $_son) { ?>
         <!-- a标签格式 重新定义或添加新 class -->
         <a class="dropdown-item" href="<?php echo $_son['url'];?>" <?php if ($_son['category'] == 3){echo 'target="_blank"';}?>>
            <i class="icon-circle-o d-md-none"></i>&nbsp;<?php echo $_son['name'];?>
         </a>
         <?php } ?>
      </div>
      <?php }?>
   </li>
   <?php }} ?>
</ul>


第二种:点击频道后进入频道页面后,显示的横向子导航。

(1)频道页面使用的代码:

<?php if ($forum_nav[$forum['fid']]['son']) { ?>
<div class="container">
    <ul class="nav">
        <?php $forum_nav = category_tree($forum_nav); foreach($forum_nav[$forum['fid']]['sonlist'] as $_forum) { ?>
        <li class="nav-item" fid="<?php echo $_forum['fid'];?>" data-active="fid-<?php echo $_forum['fid'];?>">
            <a class="nav-link" href="<?php echo url("forum-$_forum[fid]");?>">
            <?php echo $_forum['name'];?>
            </a>
        </li>
        <?php } ?>
    </ul>
</div>
<?php } ?>

(2)子栏目页面使用的代码:

<?php if ($forum_nav[$forum['fup']]['son']) { ?>
<div class="container">
    <ul class="nav">
    <?php $forum_nav = category_tree($forum_nav); foreach($forum_nav[$forum['fup']]['sonlist'] as $_forum) { ?>
        <li class="nav-item" fid="<?php echo $_forum['fid'];?>" data-active="fid-<?php echo $_forum['fid'];?>">
            <a class="nav-link" href="<?php echo url("forum-$_forum[fid]");?>">
            <?php echo $_forum['name'];?>
            </a>
        </li>
    <?php } ?>
    </ul>
</div>
<?php } ?>