Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7522027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:24:06+00:00 2026-05-30T02:24:06+00:00

I have a navigation, where I echo out the class based on the variable

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:24:08+00:00Added an answer on May 30, 2026 at 2:24 am

    I don’t see why this would improve your code, but you can try this:

    PHP:

    function activeNav($page, $current) {
        return ($page == $current) ? "active" : "inactive";
    }
    

    HTML:

    <li class="<?php echo activeNav($page, 'home'); ?>">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these tabs on my navigation: <li<?php if ($thisPage==Customers) echo class=\current\; ?>><a href=/customers/>Customers</a></li>
In pyroCMS it echo's its navigation like: <li class=last current> <a href=http://develop.jzm.co.nz/pyrocms/portfolio>portfolio</a> </li> What
I have a link that looks like this: <p class=half_text> <?php echo $upvotes; ?>
I am having some issues trying to create page navigation using php, I have
Imagine I have a navigation bar in my page header, with a number of
Hi I'm trying to generate my websites navigation/page buttons and give the active page
I currently have a script that outputs a secondary navigation based on the site
I have a navigation on my page with elements, about us, what we do,
I have a drop-down navigation that brings the user to the page selected in
Basically I have an index.php file with navigation in form of includes only .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.