PHP-制作动态导航栏



我的导航栏(仅限HTML(:

<ul class="navbar-nav m-auto">
<li class="nav-item active"><a href="<?= base_url('Home')?>" class="nav-link">Beranda</a></li>
<li class="nav-item"><a href="<?= base_url('Karya')?>" class="nav-link">Paket Wisata</a></li>
<li class="nav-item"><a href="<?= base_url('Foto')?>" class="nav-link">Foto</a></li>
<li class="nav-item"><a href="<?= base_url('Contact')?>" class="nav-link">Kontak</a></li>
</ul>

我的导航栏(php版本(

<ul class="navbar-nav m-auto">
<li <?php if ($active=='beranda') { echo 'class="nav-item active"'; } ?>><a href="<?= base_url('Home')?>" class="nav-link">Beranda</a></li>
<li <?php if ($active=='karya') { echo 'class="nav-item active"'; } ?>><a href="<?= base_url('Karya')?>" class="nav-link">Paket Wisata</a></li>
<li <?php if ($active=='foto') { echo 'class="nav-item active"'; } ?>><a href="<?= base_url('Foto')?>" class="nav-link">Foto</a></li>
<li <?php if ($active=='kontak') { echo 'class="nav-item active"'; } ?>><a href="<?= base_url('Contact')?>" class="nav-link">Kontak</a></li>
</ul>

导航栏的PHP版本不工作:请帮助我

您忘记放置else语句,请尝试此

<ul class="navbar-nav m-auto">
<li <?=($active=='beranda')?'class="nav-item active"':'nav-item';?>><a href="<?= base_url('Home')?>" class="nav-link">Beranda</a></li>
<li <?=($active=='karya')?'class="nav-item active"':'nav-item';?>><a href="<?= base_url('Karya')?>" class="nav-link">Paket Wisata</a></li>
<li <?=($active=='foto')?'class="nav-item active"':'nav-item';?>><a href="<?= base_url('Foto')?>" class="nav-link">Foto</a></li>
<li <?=($active=='kontak')?'class="nav-item active"':'nav-item';?>><a href="<?= base_url('Contact')?>" class="nav-link">Kontak</a></li>
</ul>

相关内容

  • 没有找到相关文章

最新更新