
Chris
Staff

Dec 14, 2010, 5:12 PM
Post #40 of 63
(12602 views)
Shortcut
|
|
Re: [mohabsi] Multi-level Category Functions
[In reply to]
|
Can't Post
|
|
Hi mohabsi, Try adding this code at the bottom of your STEP 1:
$categoryHtml = array( // rules for depth = 0 array( 'item_start' => '', 'sub_list_start' => '<div class="submenu"><ul>', 'sub_list_end' => '</ul></div>', 'item_end' => '' ), // rules for any greater depths array( 'item_start' => '<li>', 'sub_list_start' => '<ul>', 'sub_list_end' => '</ul>', 'item_end' => '</li>' ), ); generateCategoryStartAndEndTags($categoriesRecords, $categoryHtml); function generateCategoryStartAndEndTags(&$records, $html) { $currentDepth = 0; array_push($records, array('depth' => 0)); for ($i = 0; $i < sizeof($records); $i++) { $records[$i]['_listItemStart'] = ''; $records[$i]['_listItemEnd'] = ''; // close item unless we'll be increasing depth (in which case, we'll close it when the depth returns to this level) if ($currentDepth <= $records[$i]['depth']) { $records[$i]['_listItemEnd'] .= $html[min($currentDepth, sizeof($html)-1)]['item_end']; } // close lists and items as we decrease depth for (; $currentDepth > $records[$i]['depth']; $currentDepth--) { $records[$i-1]['_listItemEnd'] .= $html[min($currentDepth - 1, sizeof($html)-1)]['sub_list_end']; $records[$i-1]['_listItemEnd'] .= $html[min($currentDepth - 1, sizeof($html)-1)]['item_end']; } // open lists as we increase depth (this will only ever happen once at a time) for (; $currentDepth < $records[$i]['depth']; $currentDepth++) { $records[$i]['_listItemStart'] .= $html[min($currentDepth, sizeof($html)-1)]['sub_list_start']; } // open an item every time we display an item $records[$i]['_listItemStart'] .= $html[min($currentDepth, sizeof($html)-1)]['item_start']; } array_pop($records); } You will likely need to change the name of your categories variable to match your section name, shown in red above. Does that help? Please let me know if you have any questions. Chris
|