Page 1 of 1

Arranging Array...

Posted: Wed Jun 24, 2009 2:52 pm
by tymlls05
I have a javascript menu I am attempting to convert to PHP so for search engine compatability.

I have generated an array::

Code: Select all

Array ( [0] => Array ( [0] => Array ( [kei] => 60 [parent] => 0 [lpos] => 1 [name] => Home [url] => index.php ) [1] => Array ( [kei] => 61 [parent] => 0 [lpos] => 2 [name] => About Us [url] => page.php?kei=24 ) [2] => Array ( [kei] => 72 [parent] => 0 [lpos] => 3 [name] => Agents [url] => staff.php ) [3] => Array ( [kei] => 83 [parent] => 0 [lpos] => 4 [name] => Sell A Home [url] => # ) [4] => Array ( [kei] => 85 [parent] => 0 [lpos] => 5 [name] => Buy A Home [url] => # ) [5] => Array ( [kei] => 66 [parent] => 0 [lpos] => 6 [name] => Search Listings [url] => idx.php?newsearch=true ) [6] => Array ( [kei] => 64 [parent] => 0 [lpos] => 7 [name] => Commercial [url] => idx.php?format=4&offset=0 ) [7] => Array ( [kei] => 65 [parent] => 0 [lpos] => 8 [name] => Land [url] => idx.php?format=3&offset=0 ) [8] => Array ( [kei] => 68 [parent] => 0 [lpos] => 9 [name] => Photos [url] => nimbus.php ) [9] => Array ( [kei] => 69 [parent] => 0 [lpos] => 10 [name] => Links [url] => links.php ) [10] => Array ( [kei] => 70 [parent] => 0 [lpos] => 11 [name] => Contact Us [url] => page.php?kei=23 ) [11] => Array ( [kei] => 73 [parent] => 0 [lpos] => 12 [name] => Careers [url] => page.php?kei=120 ) [12] => Array ( [kei] => 88 [parent] => 0 [lpos] => 13 [name] => Agent Login [url] => http://agents.allisonlacy.com ) ) [73] => Array ( [0] => Array ( [kei] => 74 [parent] => 73 [lpos] => 0 [name] => Licensing [url] => page.php?kei=27 ) [1] => Array ( [kei] => 81 [parent] => 73 [lpos] => 1 [name] => Is Real Estate For You? [url] => page.php?kei=28 ) [2] => Array ( [kei] => 77 [parent] => 73 [lpos] => 2 [name] => Why Allison-Lacy? [url] => page.php?kei=38 ) [3] => Array ( [kei] => 90 [parent] => 73 [lpos] => 3 [name] => All About Allison-Lacy [url] => page.php?kei=120 ) [4] => Array ( [kei] => 89 [parent] => 73 [lpos] => 4 [name] => Preparing for Your Interview [url] => page.php?kei=106 ) [5] => Array ( [kei] => 80 [parent] => 73 [lpos] => 5 [name] => Contact Us [url] => page.php?kei=23 ) [6] => Array ( [kei] => 87 [parent] => 73 [lpos] => 6 [name] => Referral Program [url] => page.php?kei=30 ) ) [83] => Array ( [0] => Array ( [kei] => 84 [parent] => 83 [lpos] => 0 [name] => Homeseller Tips [url] => page.php?kei=32 ) [1] => Array ( [kei] => 62 [parent] => 83 [lpos] => 1 [name] => Properties Search [url] => idx.php?format=1&offset=0 ) ) [85] => Array ( [0] => Array ( [kei] => 63 [parent] => 85 [lpos] => 5 [name] => Properties Search [url] => idx.php?office=40&offset=0 ) ) )

The prettier version is this::

Code: Select all

 
KEI: 60, Parent: 0, Lpos:1, Home
KEI: 61, Parent: 0, Lpos:2, About Us
KEI: 72, Parent: 0, Lpos:3, Agents
KEI: 83, Parent: 0, Lpos:4, Sell A Home
KEI: 85, Parent: 0, Lpos:5, Buy A Home
KEI: 66, Parent: 0, Lpos:6, Search Listings
KEI: 64, Parent: 0, Lpos:7, Commercial
KEI: 65, Parent: 0, Lpos:8, Land
KEI: 68, Parent: 0, Lpos:9, Photos
KEI: 69, Parent: 0, Lpos:10, Links
KEI: 70, Parent: 0, Lpos:11, Contact Us
KEI: 73, Parent: 0, Lpos:12, Careers
KEI: 88, Parent: 0, Lpos:13, Agent Login
KEI: 74, Parent: 73, Lpos:0, Licensing
KEI: 81, Parent: 73, Lpos:1, Is Real Estate For You?
KEI: 77, Parent: 73, Lpos:2, Why Allison-Lacy?
KEI: 90, Parent: 73, Lpos:3, All About Allison-Lacy
KEI: 89, Parent: 73, Lpos:4, Preparing for Your Interview
KEI: 80, Parent: 73, Lpos:5, Contact Us
KEI: 87, Parent: 73, Lpos:6, Referral Program
KEI: 84, Parent: 83, Lpos:0, Homeseller Tips
KEI: 62, Parent: 83, Lpos:1, Properties Search
KEI: 63, Parent: 85, Lpos:5, Properties Search

I've been able to sort it by it's parent category and list position, but i am trying to create a submenu out of this array. So that if Parent==KEI, that row of information is inserted under it's parent.

In order to see what I am trying to attempt, it is the main menu on the left of AllisonLacy.com. The current menu, like I said, is in javscript.

Thanks in advance for the guidance.

Re: Arranging Array...

Posted: Wed Jul 01, 2009 2:58 pm
by McInfo
Making that page search-engine-friendly has less to do with PHP and more to do with using <a> tags rather than Javascript onClick events for page navigation. If the page is navigable with CSS and Javascript disabled, it can be navigated by a search engine. You can still use Javascript to make the sub-menus appear.

I suggest you design the page so it is usable with CSS disabled. That means the navigation menu should be a hierarchical list.

Code: Select all

<ul>
    <li><a href="index.php">Home</a></li>
    <li><a href="page.php?kei=24">About Us</a></li>
    <li><a href="#">Sell A Home</a>
        <ul>
            <li><a href="page.php?kei=32">Homeseller Tips</a></li>
            <li><a href="idx.php?format=1&offset=0">Properties Search</a></li>
        </ul>
    </li>
    <li><a href="page.php?kei=23">Contact Us</a></li>
</ul>
Here are some related topics on menus with submenus:
Edit: This post was recovered from search engine cache.

Re: Arranging Array...

Posted: Wed Jul 01, 2009 3:10 pm
by BornForCode
What you need is ti create a recursive function that is building your menu and submenu's.
An example to build it is:

Code: Select all

 
function display_menu($m) {
    foreach ($m as $section => $link) {
        if (!is_array($link))
            echo "<ul><li><a href='{$link}'>{$section}</a></li></ul>";
        else {
            echo "<ul><li>{$section}";
            display_menu($link);
            echo '</li></ul>';
        } // end of else
    } // end of foreach loop
} // end of function
 
display_menu($menu);