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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:18:11+00:00 2026-05-22T00:18:11+00:00

In ASP.Net I usually drive my primary navigation using a standard web.sitemap file such

  • 0

In ASP.Net I usually drive my primary navigation using a standard web.sitemap file such as the following:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="~/index.html" title="My Awesome Site">
        <siteMapNode url="~/About/index.html" title="About">
            <siteMapNode url="~/About/Board.html" title="Board"/>
            <siteMapNode url="~/About/Vision.html" title="Vision"/>
            <siteMapNode url="~/About/Mission.html" title="Mission"/>
            <siteMapNode url="~/About/Support.html" title="Support"/>
            <siteMapNode url="~/About/Locations.html" title="Locations"/>
            <siteMapNode url="~/About/Funding-Sources.html" title="Funding Sources"/>
            <siteMapNode url="~/About/Volunteer.html" title="Volunteer"/>
            <siteMapNode url="~/About/Staff.html" title="Staff"/>
        </siteMapNode>
        <siteMapNode url="~/Parents/index.html" title="Parents">
            <siteMapNode url="~/Parents/Child-Development.html" title="Child Development"/>
            <siteMapNode url="~/Parents/Referrals.html" title="Referrals"/>
        </siteMapNode>
        <siteMapNode url="~/Resources/index.html" title="Resources">
            <siteMapNode url="~/Resources/Resource-Library.html" title="Resource Library"/>
            <siteMapNode url="~/Resources/Links.html" title="Links"/>
        </siteMapNode>
    </siteMapNode>
</siteMap>

Then I usually create a user control for the navigation where I can use SiteMap.CurrentNode and/or SiteMap.CurrentNode.IsDescendantOf to mark the current page as “selected” or whatever. I’m looking for something similar for PHP. In ASP classic we would pretty much have to use an include and a bunch of if statements which works but once you get a couple of levels deep you end up with a bunch of code. I could probably create variables at the top of each page designating which “section”, “subsection” and “page” we’re on but I’d like to avoid that if possible.

I found this link which bounces things through the querystring but that’s not an option.

If anyone’s not familiar with the web.sitemap file I can explain it in more detail if needed.

EDIT – Comments for @BrandonS

The core of what I’m looking for is to be able to define a single file that represents the pages of my site. ASP.Net uses an XML file which is convenient for catching some potential errors but isn’t required. Ideally I’d actually like to use exact same file format used by ASP.Net so that I can share code but still not absolutely required.

In ASP.Net, using the sitemap above I would have a user control (basically a glorified include file) that outputs the <title> tag on every page. On the Home page it would output just My Awesome Site, on the About L2 page it would output My Awesome Site - About and on the Board L3 page it would output My Awesome Site - About - Board. The same idea might be used for breadcrumbs on subpages. (Quick aside, for all of my sites pages exist only once so there’s no chance of a page having two parents.)

In ASP.Net on every page request a SiteMap object gets automatically created. (Actually I think its lazy-loaded meaning it actually doesn’t get created unless you try accessing but that happens transparently.) So at any given moment I can use a SiteMap.CurrentNode object on any page that exists in the sitemap file. (If the page doesn’t exist in the sitemap file null is returned.) From that I can ask for the SiteMap.CurrentNode.ParentNode or I can walk the SiteMap.CurrentNode.ChildNodes. I can also get the SiteMap.RootNode which represents the root of the sitemap file. From that I can walk the SiteMap.RootNode.ChildNodes knowing that these direct children represent the Level 2 pages of my site. I can then walk these children individually knowing that each “grandchild” represents an L3 and so on.

So using the above recursion I could define my site’s primary navigation by walking the root node’s children and if I’ve got dropdown menus in my nav then I can walk the sub-children. While walking the children or grandchildren I can set classes based on if the SiteMap.CurrentNode equals or is descended from the child or grandchild. Below is an example in VB.Net of how I use the sitemap for building an L2 navigation:

    ''//An array that we append potential CSS class names to such as "first" or "active"
    Dim Classes As List(Of String)

    ''//A StringBuild is just an efficient way to work with Strings
    ''//if you are not familiar with it just now that Append() is basically "&=" and AppenLine() is basically "&= ...\n"
    Dim Buf As New StringBuilder()
    Buf.AppendLine("     <ul>")

    ''//Walk the root child nodes, the N variable will be the current ChildNode of the SiteMap.RootNote
    For Each N As SiteMapNode In SiteMap.RootNode.ChildNodes

        ''//For the first and last child we want to add extra classes in case we need to adjust borders, padding, etc
        Classes = New List(Of String)
        If N.PreviousSibling Is Nothing Then
            Classes.Add("first")
        ElseIf N.NextSibling Is Nothing Then
            Classes.Add("last")
        End If

        ''//See if the page being requested is the current child or if the current page is descended from it so that we can mark it as active
        If SiteMap.CurrentNode IsNot Nothing Then
            If SiteMap.CurrentNode.Equals(N) OrElse SiteMap.CurrentNode.IsDescendantOf(N) Then
                Classes.Add("active")
            End If
        End If

        ''//This code below is just for outputting the <li class="..."><a href="...">...</a></li> code

        ''//Write the opening list tag
        Buf.Append("      <li")
        ''//If the above code created any CSS classes append the class attribute and the space-delimited list of classes
        If Classes.Count > 0 Then
            Buf.Append(" class=""" & Join(Classes.ToArray(), " ") & """")
        End If
        ''//Close the list tag
        Buf.Append(">")

        ''//Append the hyperlink. The "N" object is the current child of the SiteMap.RootNode.ChildNodes
        ''//All SiteMapNode objects have a Url property and a Title property which is defined in the XML file
        Buf.AppendFormat("<a href=""{0}"">{1}</a></li>", N.Url.Replace("/index.html", "/"), HttpUtility.HtmlEncode(N.Title))

        ''//Append a blank line, I like to keep my code formatted nicely
        Buf.AppendLine()
    Next

    ''//Append the closing list tag
    Buf.AppendLine("     </ul>")

Additional note

Some people might think that this is overkill but this is all built into .Net, that’s why I’m asking if something exists for PHP. I could roll my own but obviously I’d like to avoid it if possible.

  • 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-22T00:18:12+00:00Added an answer on May 22, 2026 at 12:18 am

    Hmm… As I know, there are no built-in solutions in PHP. They are in a plenty of frameworks.

    For example in Zend we have navigation containers, that could store all data in any format you choose — xml-config for example. And then with help of zend view navigation helpers we could output it in our layout or in concrete page.

    As an example you could see autotranslated post about it here.

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

Sidebar

Related Questions

How do people usually detect the MIME type of an uploaded file using ASP.NET?
I'm writing an app using asp.net-mvc deploying to iis6. I'm using forms authentication. Usually
In my asp.net-mvc website I have a field that usually has a string (from
I usually create ASP.NET websites and have a few classes I use, mainly a
ASP.NET MVC has been discussed on this forum a few times. I'm about to
ASP.NET server-side controls postback to their own page. This makes cases where you want
ASP.NET 2.0 provides the ClientScript.RegisterClientScriptBlock() method for registering JavaScript in an ASP.NET Page. The
ASP.NET 1.1 - I have a DataGrid on an ASPX page that is databound
ASP.Net: In code-behind I can simulate <%# Eval(Property)%> with a call to DataBinder.Eval(myObject,Property); How
ASP.Net 3.5 running under IIS 7 doesn't seem to allow this out of the

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.