I have a navigation, where I echo out the class based on the variable on the page.
<ul class="nav">
<li class="<?php echo ($page == 'home' ? 'active' : 'inactive'); ?>" class="nav-active"><a href="/" title="Home Page">Home</a></li>
<li class="<?php echo ($page == 'home' ? 'active' : 'inactive'); ?>" class="nav-active"><a href="/" title="Another Page Page">Another Page</a></li>
</ul>
I am new to PHP and I’m trying to figure out how I’ would make it into a function so I can just called it and add the arguments.
<li class="<php activeNav($page, $current); ?>">
Can someone explain how to do this? And sorry for not giving a very descriptive title, don’t know what to call it.
I don’t see why this would improve your code, but you can try this:
PHP:
HTML: