* @version 1.1.0 * * @package WordPress * @subpackage Administration */ function wp_custom_navigation_get_menu_items( $menu_objects, $key = 'ID' ) { $menu_items = array(); if ( !empty( $menu_objects ) && !empty( $key ) ) { $args = array( 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish' ); if ( count( $menu_objects ) > 1 ) $args['include'] = implode( ',', $menu_objects ); else $args['include'] = $menu_objects[0]; $posts = get_posts( $args ); if ( ! empty( $posts ) ) { foreach ( $posts as $post ) { $menu_items[ $post->$key ] = $post; } } unset( $posts ); ksort( $menu_items ); } return $menu_items; } function wp_custom_navigation_setup($override = false) { $nav_version = '1.1.0'; //Custom Navigation Menu Setup //Check for Upgrades if (get_option('wp_settings_custom_nav_version') <> '') { $nav_version_in_db = get_option('wp_settings_custom_nav_version'); } else { $nav_version_in_db = '0'; } //Override for menu descriptions update_option('wp_settings_custom_nav_advanced_options','yes'); if(($nav_version_in_db <> $nav_version) || ($override)) update_option('wp_settings_custom_nav_version',$nav_version); $custom_menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) ); if ( !empty( $custom_menus ) ) { foreach( $custom_menus as $menu ) { $menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' ); if ( !empty( $menu_objects ) ) { foreach( $menu_objects as $item ) wp_delete_post( $item ); } wp_delete_term( $menu->term_id, 'nav_menu' ); } } } /*-----------------------------------------------------------------------------------*/ /* Custom Navigation Functions */ /* wp_custom_navigation_output() displays the menu in the back/frontend /* wp_custom_navigation_sub_items() is a recursive sub menu item function /* wp_custom_nav_get_pages() /* wp_custom_nav_get_categories() /* wp_custom_navigation_default_sub_items() is a recursive sub menu item function /*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/ /* Main Output Function /* args list /* type - frontend or backend /* name - name of your menu /* id - id of menu in db /* desc - 1 = show descriptions, 2 = dont show descriptions /* before_title - html before title is outputted in tag /* after_title - html after title is outputted in tag /*-----------------------------------------------------------------------------------*/ function wp_custom_navigation_output($args = array()) { //DEFAULT ARGS $type = 'frontend'; $name = 'Menu 1'; $id = 0; $desc = 2; $before_title = ''; $after_title = ''; if (isset($args)) { if ( !is_array($args) ) parse_str( $args, $args ); extract($args); } $menu_objects = get_objects_in_term( $id, 'nav_menu' ); $menu_items = wp_custom_navigation_get_menu_items( $menu_objects, 'menu_order' ); //Override for menu descriptions $advanced_option_descriptions = get_option('wp_settings_custom_nav_advanced_options'); if ( $advanced_option_descriptions == 'no' ) $desc = 2; $queried_id = 0; global $wp_query; if ( is_page() ) $queried_id = $wp_query->get_queried_object_id(); elseif ( is_category() ) $queried_id = $wp_query->get_queried_object_id(); $parent_stack = array(); $current_parent = 0; $parent_menu_order = array(); // Display Loop foreach ( $menu_items as $key => $menu_item ) { $menu_type = get_post_meta($menu_item->ID, 'menu_type', true); $object_id = get_post_meta($menu_item->ID, 'object_id', true); $parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order; if ( isset( $parent_menu_order[ $menu_item->post_parent ] ) ) $parent_item = $parent_menu_order[ $menu_item->post_parent ]; else $parent_item = 0; switch ( $menu_type ) { // Page Menu Item case 'page': if ( $menu_item->guid == '' ) $link = get_permalink( $object_id ); else $link = $menu_item->guid; if ( $menu_item->post_title == '' ) $title = htmlentities( get_the_title( $object_id ) ); else $title = htmlentities( $menu_item->post_title ); if ( $menu_item->post_content == '' ) $description = htmlentities( get_post_meta( $menu_item->ID, 'page-description', true ) ); else $description = htmlentities( $menu_item->post_content ); $target = ''; break; // Category Menu Item case 'category': if ( $menu_item->guid == '' ) $link = get_category_link( $object_id ); else $link = $menu_item->guid; if ( $menu_item->post_title == '' ) { $title_raw = get_categories( array('include' => $object_id) ); $title = htmlentities($title_raw[0]->cat_name); } else { $title = htmlentities( $menu_item->post_title ); } if ( $menu_item->post_content == '' ) $description = htmlentities( strip_tags( category_description( $object_id ) ) ); else $description = htmlentities( $menu_item->post_content ); $target = ''; break; default: // Custom Menu Item $link = $menu_item->guid; $title = htmlentities( $menu_item->post_title ); $description = htmlentities( $menu_item->post_content ); $target = 'target="_blank"'; break; } $li_class = ''; /* @todo: update to use tax/post data //SET anchor title if (isset($wp_custom_nav_menu_items->custom_anchor_title)) { $anchor_title = htmlentities($wp_custom_nav_menu_items->custom_anchor_title); } else { $anchor_title = $title; } if ($queried_id == $wp_custom_nav_menu_items->post_id) { $li_class = 'class="current_page_item"'; } if (isset($wp_custom_nav_menu_items->new_window)) { if ($wp_custom_nav_menu_items->new_window > 0) { $target = 'target="_blank"'; } else { $target = ''; } } */ // List Items ?> post_parent != $current_parent ) ) { ?> ID; ?>