Navigo – Navigation / split Level1 and Level2
-
Hi all
I need some help modifing the Navigation Plugin “Navigo” from https://www.adahas.com/work/navigo/.
Usualy Navigo creates nested Lists for Submenu-Pages Like:
<ul id="level1"> <li id="level1active"><a id="level1current" href="" title="Link1">Link1</a> <ul id="level2"> <li><a href="" title="Level2 Link">Level2 Link</a></li> </ul> </li> </ul>
Because I want to create the Level1 Navigation with Cufon Font Replacement, I should have Level2 outside of the active li, like…
<ul id="level1"> <li id="level1active"><a id="level1current" href="" title="Link1">Link1</a></li> <ul id="level2"> <li><a href="" title="Level2 Link">Level2 Link</a></li> </ul> </ul>
Would be very grateful if someone can help me out with this issue because my PHP-Skills aren`t that good.
Here is the navigo.php File that creates the nested Lists.
load_plugin_textdomain('navigo'); function navigo($args = '', $from_page_content = false) { $content = ''; global $wp_query; $queried_obj = $wp_query->get_queried_object(); // parse all args, and if not specified, initialize to defaults parse_str($args, $r); if (!isset($r['child_of'])) $r['child_of'] = 0; if (!isset($r['depth'])) $r['depth'] = 0; if (!isset($r['hidden_depth'])) $r['hidden_depth'] = 0; if (!isset($r['collapse'])) $r['collapse'] = false; if (!isset($r['leading_tabs'])) $r['leading_tabs'] = 2; if (!isset($r['sort_column'])) $r['sort_column'] = ''; if (!isset($r['exclude'])) $r['exclude'] = ''; // get all page information $pages_params = ''; if(strlen($r['sort_column']) > 0) $pages_params = 'sort_column=' . $r['sort_column']; if(strlen($r['exclude']) > 0){ $pages_params = $pages_params.'&exclude='.$r['exclude']; } $pages = get_pages($pages_params); if ( $pages ) { // construct the page tree $page_tree = array(); // collect all page ids $keys = array_keys($pages); $indexes = array(); for($i = 0; $i < sizeof($keys); $i++) { $indexes[$keys[$i]] = $pages[$keys[$i]]->ID; } // collect all parent ids $parents = array(); $child_id = $queried_obj->ID; while($child_id != 0) { $parent_id = $pages[array_search($child_id, $indexes)]->post_parent; array_push($parents, $parent_id); $child_id = $parent_id; } // clear parent if root differs from the current page root if($r['child_of'] != 0 && !strcmp(array_search($r['child_of'], $parents), '') ) { $parents = array(); } foreach($pages as $page) { $page_tree[$page->ID]['title'] = $page->post_title; $page_tree[$page->ID]['name'] = $page->post_name; $page_tree[$page->post_parent]['children'][] = $page->ID; } // prepare indentation level $indent = ""; for($i = 0; $i < ($r['leading_tabs'] - $r['hidden_depth']); $i++) { $indent .= "\t"; } // root list element - start if($r['hidden_depth'] < 1) { $id = 'level1'; if(isset($r[$id])) $id = $r[$id]; $attribute = "class"; if($r['collapse']) $attribute = "id"; $content .= "\n" . $indent . '<ul ' . $attribute . '="' . $id . '">'; } // method call to display level $content .= _navigo_subs($r['child_of'], $page_tree, $r, $parents, $pages, $indexes, $queried_obj, 1); // root list element - end if($r['hidden_depth'] < 1) { $content .= "\n" . $indent . '</ul>'; } } if($from_page_content) return $content; else echo($content); } function _navigo_subs($parent, $page_tree, $r, $parents, $pages, $indexes, $queried_obj, $current_level) { $content = ''; foreach($page_tree[$parent]['children'] as $page_id) { // get a reference to the current page for easy access $cur_page = $page_tree[$page_id]; // prepare indentation level $indent = ""; for($i = 0; $i < ($r['leading_tabs'] + $current_level - $r['hidden_depth']); $i++) { $indent .= "\t"; } // prepare current and active ids $active = ''; $current = ''; $attribute = "class"; if($r['collapse']) $attribute = "id"; // prepare ids for active and current elements if(in_array($page_id, $parents) || $page_id == $queried_obj->ID) { $id = 'level' . $current_level; if(isset($r[$id])) $id = $r[$id]; $active = ' ' . $attribute . '="' . $id . 'active"'; if(in_array($page_id, $parents)) { $current = ' ' . $attribute . '="' . $id . 'highlight"'; } else { $current = ' ' . $attribute . '="' . $id . 'current"'; } } } // end list item elements if hidden depth not exceeded if( $r['hidden_depth'] < $current_level) { $content .= '</li>'; } // start list item element if hidden depth not exceeded if( $r['hidden_depth'] < $current_level) { $content .= "\n" . $indent . '<li' . $active . '>'; $content .= '<a' . $current . ' href="' . get_page_link($page_id) . '" title="' . wp_specialchars($cur_page['title']) . '">' . $cur_page['title'] . '</a>'; } // restrict dispaying if collapsable mode if((! $r['collapse']) || (in_array($page_id, $parents) || $page_id == $queried_obj->ID)) { // check whether element is a leaf node if(isset($cur_page['children']) && is_array($cur_page['children'])) { // check for display depth limit if($r['depth'] > $current_level || $r['depth'] == 0) { // sub list element - start $id = 'level' . ($current_level + 1); if(isset($r[$id])) $id = $r[$id]; $content .= "\n" . $indent . '<ul ' . $attribute . '="' . $id . '">'; // method call to display level $content .= _navigo_subs($page_id, $page_tree, $r, $parents, $pages, $indexes, $queried_obj, $current_level + 1); // sub list element - start $content .= "\n" . $indent . '</ul>'; } }} return $content; } // replace placeholder by generated code function navigo_insert( $content ) { $matches = array(); if(preg_match('#<!--navigo:(.*)-->#', $content, $matches)) { $replace_string = '<!--navigo:' . $matches[1] . '-->'; $matches[1] = str_replace(', ', '&', $matches[1]); $content = str_replace($replace_string, navigo(trim($matches[1]), true), $content); } return $content; } function navigo_admin_include() { include(dirname(__FILE__).'/navigo-options.php'); } // display options tab in wp-admin function navigo_options_page() { add_options_page('navigo Options', 'navigo', 8, __FILE__, 'navigo_admin_include'); } // add actions and filters add_action('admin_menu', 'navigo_options_page', 8); add_filter('the_content', 'navigo_insert', 7); ?>
- The topic ‘Navigo – Navigation / split Level1 and Level2’ is closed to new replies.