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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 120k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Not with the runtime. All message sends ultimately work out… May 12, 2026 at 12:17 am
  • Editorial Team
    Editorial Team added an answer My favourites are Fast Reports and Excel. I use fast… May 12, 2026 at 12:17 am
  • Editorial Team
    Editorial Team added an answer Why don't you keep a hash (a JavaScript {} object)… May 12, 2026 at 12:17 am

Related Questions

Alright, I am going to state up front that this question may be too
I am attempting to write an ASP.net web service that will be utilized by
How do I attach an onclick event to a link_to_function such that clicking on
I am trying to get LINQ to SQL to persist changes to an attached

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.