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 6674477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:45:02+00:00 2026-05-26T03:45:02+00:00

Im developing a website and I am trying to a foreach include for my

  • 0

Im developing a website and I am trying to a foreach include for my header which includes my navigation menu (the main topic here).

My code inside the header.php file for the navigation menu is here:

<!-- topmenu -->  
<div class="menu-header">
    <div class="container">
            <ul class="top menu">
            <?php
            $nav = array("Home","About","Portfolio","Products","Services","Contact");
            foreach($nav as $item){
            if($item == $title){
                echo "<li class='current-menu-ancestor parent'><a href='$item.php'>$item</a></li>";
                }else{
                echo "<li><a href='$item.php'>$item</a></li>"; }
                }
                ?>

          </ul>
        </div>
</div>        
<!--/ topmenu -->

You may notice that in the code is the condition if($item == $title). In my index.php I have included $title="Home"; which I intended to be taken and used in this if statement.

On my index.php page I have included this with the following code:

<?php
    include("header.php");
$title = "Home";
?>

Can anyone tell me where I am going wrong?

  • 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-26T03:45:02+00:00Added an answer on May 26, 2026 at 3:45 am

    Not an answer, but comments aren’t suitable for formatted code. You might want to de-duplicate some of your HTML:

    $class = '';
    if($item == $title) {
        $class = ' class"current-menu-ancestor parent"';
    }
    
    echo "<li{$class}><a href='$item.php'>$item</a></li>";
    

    Duplicating HTML as you did can lead to maintenance problems later on, if you decide to change something in the menu structure and change only one of the copies of the menu html.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a website and for the main navigation, I was thinking it
I'm trying my luck here. I am currently developing a website wherein people should
Developing a website and just trying to get back into the swing of (clever)
We're developing an EPiServer-based website and trying to deploy our latest build onto a
I'm developing an object-oriented PHP website right now and am trying to determine the
Currently I am developing website in asp.net. I wanted to include spellchecker module into
I am developing a C#/SQL VS 2008 website application and I'm trying to set
I am developing a website in flex. And in that, i am trying to
am new to StackOverflow.. I am developing a website which requires extensive ORM...using asp.net
here's my question, i'm developing a personal website that has a huge animation in

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.