Building a website using a PHP based Ecommerce product Magento.
The problem I have is that I want to use tabbed navigation.
My idea was to use CSS to show the TAB over the relevant Navigation menu item based on the URL.
However, one URL always changes, so I wanted to somehow use an ifelse statement.
I’ve come up with two methods that I think could work, could any experts tell me what they would think is best and how they would implement it?
Method 1
<div id="nav">
<ul id="mainnav">
<li><a href="index.php" title="Welcome page" <?php if ($page == 'index.php') { ?>class="active"<?php } ?>>Welcome</a></li>
<li><a href="about_us.php" title="About us page" <?php if ($page == 'about_us.php') { ?>class="active"<?php } ?>>About us</a></li>
<li><a href="services.php" title="Services page" <?php if ($page == 'services.php') { ?>class="active"<?php } ?>>Services</a></li>
<li><a href="testimonials.php" title="Testimonials page" <?php if ($page == 'testimonials.php') { ?>class="active"<?php } ?>>Testimonials</a></li>
<li><a href="contact_us.php" title="Contact us page" <?php if ($page == 'contact_us.php') { ?>class="active"<?php } ?>>Contact us</a></li>
else
<li><a href="store.php" title="Store Page" <?php ($page == 'store.php') { ?>class="active"<?php } ?>>Store</a></li>
</ul>
</div>
Method 2
$URL = store.php;
SWITCH ($sample) {
CASE home.php:
<li><a href="index.php" title="Welcome page" <?php if ($page == 'index.php') { ?>class="active"<?php } ?>>Welcome</a></li>
break;
CASE services.php:
<li><a href="services.php" title="Services page" <?php if ($page == 'services.php') { ?>class="active"<?php } ?>>Services</a></li>
break;
CASE aboutus.php:
<li><a href="about_us.php" title="About us page" <?php if ($page == 'about_us.php') { ?>class="active"<?php } ?>>About us</a></li>
break;
DEFAULT:
<li><a href="store.php" title="Store Page" <?php ($page == 'store.php') { ?>class="active"<?php } ?>>Store</a></li>
}
If this is the final form of the menu, how about abstracting it in an array?
this way, you’d have to only edit the array in the long run.