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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:51:13+00:00 2026-05-11T15:51:13+00:00

I am attemptting to attach a small CMS to a website I am creating.

  • 0

I am attemptting to attach a small CMS to a website I am creating. However I have come across a small problem. The CMS uses PHP functions for inserting menus, these PHP functions create the HTML. The particular function I wish to use (treemenu) creates a nested ul li that can then be used for a drop down menu. However the nested ul li is structured like so:

<li>Projects (Menu Level 1)</li>     <ul>         <li>Project 1 (Menu Level 2)</li>         <li>Project 2 (Menu Level 2)</li>         <li>Project 3 (Menu Level 2)</li>     </ul> <li>News (Menu Level 1)</li> <li>Contact (Menu Level 1)</li> 

When creating a drop down menu in CSS I believe the Menu Level 1 li should wrap its children like so:

<li>Projects (Menu Level 1)     <ul>         <li>Project 1 (Menu Level 2)</li>         <li>Project 2 (Menu Level 2)</li>         <li>Project 3 (Menu Level 2)</li>     </ul> </li> <li>News (Menu Level 1)</li> <li>Contact (Menu Level 1)</li> 

I have never before worked with PHP and therefore would not know how to alter the function in order to accomplish the above. I would hope it would be a simple change. Below is the PHP function that outputs the first example structure:

function treemenu($generat=0) { global $pagenum, $menu, $selected, $extension, $set; $count=0; $out='\n'; $intend=0; while($menu[$count][0] != '') {     if(strpos($menu[$count][3],'#') === false) {     if($menu[$count][2]=='0' && $intend==2) {         $intend--;         $out.='</ul>\n';     }     if($menu[$count][1]=='0' && $intend==1) {         $intend--;         $out.='</ul>\n';     }     if($menu[$count][1]!='0' && $intend<1) {         $intend=1;         $out.='<ul>\n';     }     if($menu[$count][2]!='0' && $intend<2) {         $intend=2;         $out.='<ul>\n';     }     $out.='<li class=\'LNE_menu\'><a ';     if($menu[$count][4]==$selected['name'])         $out.= 'class='selected' ';     if(strpos($menu[$count][3],'*'))         $out.='href=''.str_replace('*', '',$menu[$count][3]).''>';     elseif($generat)         $out.='href=''.$menu[$count][3].'.'.$set['extension'].''>';     else         $out.='href=''.$set['indexfile'].'?page='.$menu[$count][3].''>';     $out.=$menu[$count][4].'</a></li>\n';     }     $count++; } return $out; } 

Could anyone possibly point me in the right direction as to how to make the closing li tag of a level 1 menu item wrap the ul immediately after, as in the second example?

  • 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. 2026-05-11T15:51:14+00:00Added an answer on May 11, 2026 at 3:51 pm

    This would be a excellent example of the use of recursion. An array (with sub-arrays within it) defines each level, and a function loops, calling itself whenever it finds a new array to process. As long as the function cleans up appropriately (closing the </li> & </ol>), it’s largely automatic.

    <?php // I know which function I'd rather write.... $tree = array('Projects (Menu Level 1)',               array('Project 1 (Menu Level 2)',                     'Project 2 (Menu Level 2)',                     'Project 3 (Menu Level 2)'),               'News (Menu Level 1)',               'Contact (Menu Level 1)');  // now quake beneath the power of this fully operational recursive function! function olLiTree($tree) {     echo '<ul>';     foreach($tree as $item) {         if (is_array($item)) {             olLiTree($item);         } else {             echo '<li>', $item, '</li>';         }     }     echo '</ul>'; } olLiTree($tree);  // kick off from the top level 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two ajax functions that fetch JSON objects using .getJSON and then build
I have basically the opposite problem to this question: How to prevent iframe from
I have come to the conclusion HTML enabled JTextPanes do not support word wrapping.
Attempting to build a C# NPAPI plugin I have found a tutorial which describes
Attempting to get Spring internationalization working. I have used classpath:messages basename, created .properties files
Attempting/struggling to get registration and sign-up working within an active admin project. I have
I'm attempting to attach a file to a comment in a message with the
I detached a database, and when i try to re-attach it i am getting
I am attempting to write a C# app that will attach to the 2008
I have a little form that edits my entity. I create that entity using

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.