* @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) { // Custom Navigation Menu Setup // Override for menu descriptions update_option('wp_settings_custom_nav_advanced_options', 'yes'); $custom_menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) ); if ( !empty( $custom_menus ) ) { foreach ( $custom_menus as $menu ) { wp_custom_navigation_delete_menu( $menu->term_id ); } } } function wp_custom_navigation_delete_menu( $menu_term_id ) { $term_id = (int) $menu_term_id; if ( $term_id > 0 ) { $menu_objects = get_objects_in_term( $term_id, 'nav_menu' ); if ( !empty( $menu_objects ) ) { foreach ( $menu_objects as $item ) { wp_delete_post( $item ); } } wp_delete_term( $term_id, 'nav_menu' ); } } function setup_menu_item($menu_item, $type = 'item', $position = 0) { global $parent_menu_order; if ( 'item' == $type ) { $menu_item->type = get_post_meta($menu_item->ID, 'menu_type', true); $menu_item->object_id = get_post_meta($menu_item->ID, 'object_id', true); if ( isset( $parent_menu_order[ $menu_item->post_parent ] ) ) $menu_item->parent_item = $parent_menu_order[ $menu_item->post_parent ]; else $menu_item->parent_item = 0; } elseif ( 'category' == $type ) { $menu_item->type = $type; $menu_item->object_id = $menu_item->term_id; $menu_item->ID = $menu_item->term_id; $menu_item->parent_item = $menu_item->parent; $menu_item->menu_order = $position; } elseif ( 'page' == $type ) { $menu_item->type = $type; $menu_item->object_id = $menu_item->ID; $menu_item->parent_item = $menu_item->post_parent; $menu_item->menu_order = $position; } switch ( $menu_item->type ) { // Page Menu Item case 'page': if ( $menu_item->guid == '' ) $menu_item->link = get_permalink( $menu_item->object_id ); else $menu_item->link = $menu_item->guid; if ( $menu_item->post_title == '' ) $menu_item->title = htmlentities( get_the_title( $menu_item->object_id ) ); else $menu_item->title = htmlentities( $menu_item->post_title ); if ( $menu_item->post_content == '' ) $menu_item->description = htmlentities( get_post_meta( $menu_item->ID, 'page-description', true ) ); else $menu_item->description = htmlentities( $menu_item->post_content ); $menu_item->target = ''; $menu_item->append = 'Page'; break; // Category Menu Item case 'category': if ( empty($menu_item->guid) ) $menu_item->link = get_category_link( $menu_item->object_id ); else $menu_item->link = $menu_item->guid; if ( empty($menu_item->post_title) ) { $title_raw = get_category( $menu_item->object_id ); $menu_item->title = htmlentities($title_raw->cat_name); } else { $menu_item->title = htmlentities( $menu_item->post_title ); } if ( empty($menu_item->post_content) ) $menu_item->description = htmlentities( strip_tags( category_description( $menu_item->object_id ) ) ); else $menu_item->description = htmlentities( $menu_item->post_content ); $menu_item->target = ''; $menu_item->append = 'Category'; break; default: // Custom Menu Item $menu_item->link = $menu_item->guid; $menu_item->title = htmlentities( $menu_item->post_title ); $menu_item->description = htmlentities( $menu_item->post_content ); $menu_item->target = 'target="_blank"'; $menu_item->append = 'Custom'; break; } $menu_item->li_class = ''; global $wp_query; if ( $menu_item->ID == $wp_query->get_queried_object_id() ) $menu_item->li_class = 'class="current_page_item"'; $menu_item->anchor_title = ''; /* @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 = ''; } } */ return $menu_item; } function output_menu_item($menu_item, $context, $args = array() ) { switch( $context ) { case 'backend': case 'menu': ?>
title); ?> type); ?> <?php esc_attr_e('Edit Menu Item'); ?> <?php esc_attr_e('Remove from Custom Menu'); ?> <?php esc_attr_e('View Page'); ?>
title; ?> target; ?>>title . $args['after_title']; ?>description; ?>description; ?>
title; ?> <?php esc_attr_e('Add to Custom Menu'); ?>
tag /* after_title - html after title is outputted in tag /*-----------------------------------------------------------------------------------*/ function wp_custom_navigation_output( $args = array() ) { // Defaults $defaults = array( 'type' => 'frontend', 'name' => 'Menu 1', 'id' => 0, 'desc' => 2, 'before_title' => '', 'after_title' => ''); $args = wp_parse_args($args, $defaults); extract($args, EXTR_SKIP); $menu_objects = get_objects_in_term( $id, 'nav_menu' ); $menu_items = wp_custom_navigation_get_menu_items( $menu_objects, 'menu_order' ); $parent_stack = array(); $current_parent = 0; $parent_menu_order = array(); // Setup parentage foreach ( $menu_items as $key => $menu_item ) { $parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order; } // Display Loop foreach ( $menu_items as $key => $menu_item ) { $menu_item = setup_menu_item($menu_item); // List Items ?> post_parent != $current_parent ) ) { ?> ID; ?>