Jump to content

Is anybody know how to make a correct links(full path) to categories in case with multimenu below?


wJesus56

Recommended Posts

I'm trying to make a low-level multi-level menu from PHP array . I use lists to make the menu drop-down. I use a function to bring an array to a list, but the function I use has a problem with generating links to menu items. Is there anyone here who could help with the refinement of the function?

Example: link to bigbanans in cats2 must be:

cat2/items2/banans/bigbanans


<!DOCTYPE html>
    <html>
      <head>
        <title>jQuery Slideshow - sjoloughlin</title>
        <meta charset="utf-8">
    
    
    
    <style>
    nav ul
            {
            list-style: none;
            padding: 0;
            text-align:center;
            }
    nav li
            {
            background-color: rgba(0,100,0,0.5);
            position: relative;
            display: inline-block;
            }
    nav li:hover
            {
            background-color: rgba(100,0,0,0.5)
            }
    nav a
            {
            display:block;
            padding: 0.5em;
            text-decoration: none;
            color: rgba(0,0,100,0.9);
            }
    nav ul ul
            {
            display: none;
            position: absolute;
            }
    nav li:hover > ul
            {
            display: block;
            }
    nav ul ul ul
            {
            left: 100%;
            top: 0;
            }
    nav > ul > li > ul > li
            {
            min-width: 100%;
            }
            
            </style>
              </head>
    <?php
    function is_multidimensional(array $array) {
        return count($array) !== count($array, COUNT_RECURSIVE);
    }

function printArrayList($array, $last) { 
$pathstring ="";

echo "<ul>\n"; 

$path=$last;
foreach ($array as $k => $v)
{ 
if (strpos($k, "option")=="") { 

$path[]= $k;
}



$fullpath= implode("/", $path);

    if (is_array($v))
    {   
                echo "<li><a href=".$fullpath.">".$k."</a>\n";   
                
             if (is_multidimensional($v)) { printArrayList($v, $path); } else {  
        // unset($path); $path=array();  
             }
                 
                
                continue;
                
            }
    if (strpos($k, "option")>0) {
            } else { echo "<li>" . $k . " " . $v . ""; }   //   } else { echo "<li>" . $k . " " . $v . "</li>"; }
        
        }
    
        echo "</ul>\n";
    }
  
$menu = array(
    'Cat1' => array(
        'FORCATEGORY_NUMBER1_option' => "1",
        'FORCATEGORY_NUMBER2_option' => "2",
        'FORCATEGORY_NUMBER3_option' => "3",
        "ITEMS1" => array(
            'FORCATEGORY_NUMBER1_option' => "1",
            'FORCATEGORY_NUMBER2_option' => "2",
            'FORCATEGORY_NUMBER3_option' => "3",
            "Apples" => array(
                    'FORCATEGORY_NUMBER1_option' => "111",
                    'FORCATEGORY_NUMBER2_option' => "2",
            ),
                "Banans" => array(
                    'FORCATEGORY_NUMBER1_option' => "1",
                    'FORCATEGORY_NUMBER2_option' => "2",
            ),
        ),

         "ITEMS2" => array(
            'FORCATEGORY_NUMBER1_option' => "1",
            'FORCATEGORY_NUMBER2_option' => "2",
            'FORCATEGORY_NUMBER3_option' => "3",
            "Apples" => array(
                    'FORCATEGORY_NUMBER1_option' => "1",
                    'FORCATEGORY_NUMBER2_option' => "2",
            ),
                "Banans" => array(
                    'FORCATEGORY_NUMBER1_option' => "1",
                    'FORCATEGORY_NUMBER2_option' => "2",
            ),
        ),
        
    ) ,
	    'Cat2' => array(
        'FORCATEGORY_NUMBER1_option' => "1",
        'FORCATEGORY_NUMBER2_option' => "2",
        'FORCATEGORY_NUMBER3_option' => "3",
        "ITEMS1" => array(
            'FORCATEGORY_NUMBER1_option' => "1",
            'FORCATEGORY_NUMBER2_option' => "2",
            'FORCATEGORY_NUMBER3_option' => "3",
            "Apples" => array(
                    'FORCATEGORY_NUMBER1_option' => "1",
                    'FORCATEGORY_NUMBER2_option' => "2",
            ),
                "Banans" => array(
                    'FORCATEGORY_NUMBER1_option' => "1",
                    'FORCATEGORY_NUMBER2_option' => "2",
            ),
        ),

         "ITEMS2" => array(
            'FORCATEGORY_NUMBER1_option' => "1",
            'FORCATEGORY_NUMBER2_option' => "2",
            'FORCATEGORY_NUMBER3_option' => "3",
            "Apples" => array(
                    'FORCATEGORY_NUMBER1_option' => "1",
                    'FORCATEGORY_NUMBER2_option' => "2",
            ),
                "Banans" => array(
                    'FORCATEGORY_NUMBER1_option' => "1",
                    'FORCATEGORY_NUMBER2_option' => "2",
            ),
        ),
        
    ) ,
	
	
);


    ?>
      <body>
    <nav>
  <?PHP printArrayList($menu, $last=array());
    ?>
    </nav>
      </body>
    </html>

 

Edited by wJesus56
Link to comment
Share on other sites

We generally use the <> icon to create a box to hold the Code, not the written text that explains your topic.  Makes it much easier to read not only the code (in the box) but the text NOT in the box.  Having to scroll left and write to simply read is a pia and not worth doing.  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.