コード例 #1
0
/**
 * Displays a navigation menu.
 *
 * Optional $args contents:
 *
 * menu - The menu that is desired.  Accepts (matching in order) id, slug, name. Defaults to blank.
 * menu_class - CSS class to use for the ul element which forms the menu. Defaults to 'menu'.
 * menu_id - The ID that is applied to the ul element which forms the menu. Defaults to the menu slug, incremented.
 * container - Whether to wrap the ul, and what to wrap it with. Defaults to 'div'.
 * container_class - the class that is applied to the container. Defaults to 'menu-{menu slug}-container'.
 * container_id - The ID that is applied to the container. Defaults to blank.
 * fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'nxt_page_menu'. Set to false for no fallback.
 * before - Text before the link text.
 * after - Text after the link text.
 * link_before - Text before the link.
 * link_after - Text after the link.
 * echo - Whether to echo the menu or return it. Defaults to echo.
 * depth - how many levels of the hierarchy are to be included.  0 means all.  Defaults to 0.
 * walker - allows a custom walker to be specified.
 * theme_location - the location in the theme to be used.  Must be registered with register_nav_menu() in order to be selectable by the user.
 * items_wrap - How the list items should be wrapped. Defaults to a ul with an id and class. Uses printf() format with numbered placeholders.
 *
 * @since 3.0.0
 *
 * @param array $args Arguments
 */
function nxt_nav_menu($args = array())
{
    static $menu_id_slugs = array();
    $defaults = array('menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '', 'echo' => true, 'fallback_cb' => 'nxt_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 'depth' => 0, 'walker' => '', 'theme_location' => '');
    $args = nxt_parse_args($args, $defaults);
    $args = apply_filters('nxt_nav_menu_args', $args);
    $args = (object) $args;
    // Get the nav menu based on the requested menu
    $menu = nxt_get_nav_menu_object($args->menu);
    // Get the nav menu based on the theme_location
    if (!$menu && $args->theme_location && ($locations = get_nav_menu_locations()) && isset($locations[$args->theme_location])) {
        $menu = nxt_get_nav_menu_object($locations[$args->theme_location]);
    }
    // get the first menu that has items if we still can't find a menu
    if (!$menu && !$args->theme_location) {
        $menus = nxt_get_nav_menus();
        foreach ($menus as $menu_maybe) {
            if ($menu_items = nxt_get_nav_menu_items($menu_maybe->term_id)) {
                $menu = $menu_maybe;
                break;
            }
        }
    }
    // If the menu exists, get its items.
    if ($menu && !is_nxt_error($menu) && !isset($menu_items)) {
        $menu_items = nxt_get_nav_menu_items($menu->term_id);
    }
    // If no menu was found or if the menu has no items and no location was requested, call the fallback_cb if it exists
    if ((!$menu || is_nxt_error($menu) || isset($menu_items) && empty($menu_items) && !$args->theme_location) && $args->fallback_cb && is_callable($args->fallback_cb)) {
        return call_user_func($args->fallback_cb, (array) $args);
    }
    // If no fallback function was specified and the menu doesn't exists, bail.
    if (!$menu || is_nxt_error($menu)) {
        return false;
    }
    $nav_menu = $items = '';
    $show_container = false;
    if ($args->container) {
        $allowed_tags = apply_filters('nxt_nav_menu_container_allowedtags', array('div', 'nav'));
        if (in_array($args->container, $allowed_tags)) {
            $show_container = true;
            $class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : ' class="menu-' . $menu->slug . '-container"';
            $id = $args->container_id ? ' id="' . esc_attr($args->container_id) . '"' : '';
            $nav_menu .= '<' . $args->container . $id . $class . '>';
        }
    }
    // Set up the $menu_item variables
    _nxt_menu_item_classes_by_context($menu_items);
    $sorted_menu_items = array();
    foreach ((array) $menu_items as $key => $menu_item) {
        $sorted_menu_items[$menu_item->menu_order] = $menu_item;
    }
    unset($menu_items);
    $sorted_menu_items = apply_filters('nxt_nav_menu_objects', $sorted_menu_items, $args);
    $items .= walk_nav_menu_tree($sorted_menu_items, $args->depth, $args);
    unset($sorted_menu_items);
    // Attributes
    if (!empty($args->menu_id)) {
        $wrap_id = $args->menu_id;
    } else {
        $wrap_id = 'menu-' . $menu->slug;
        while (in_array($wrap_id, $menu_id_slugs)) {
            if (preg_match('#-(\\d+)$#', $wrap_id, $matches)) {
                $wrap_id = preg_replace('#-(\\d+)$#', '-' . ++$matches[1], $wrap_id);
            } else {
                $wrap_id = $wrap_id . '-1';
            }
        }
    }
    $menu_id_slugs[] = $wrap_id;
    $wrap_class = $args->menu_class ? $args->menu_class : '';
    // Allow plugins to hook into the menu to add their own <li>'s
    $items = apply_filters('nxt_nav_menu_items', $items, $args);
    $items = apply_filters("nxt_nav_menu_{$menu->slug}_items", $items, $args);
    $nav_menu .= sprintf($args->items_wrap, esc_attr($wrap_id), esc_attr($wrap_class), $items);
    unset($items);
    if ($show_container) {
        $nav_menu .= '</' . $args->container . '>';
    }
    $nav_menu = apply_filters('nxt_nav_menu', $nav_menu, $args);
    if ($args->echo) {
        echo $nav_menu;
    } else {
        return $nav_menu;
    }
}
コード例 #2
0
ファイル: nav-menus.php プロジェクト: nxtclass/NXTClass
// by adding a class for the max menu depth.
global $_nxt_nav_menu_max_depth;
$_nxt_nav_menu_max_depth = 0;
// Calling nxt_get_nav_menu_to_edit generates $_nxt_nav_menu_max_depth
if (is_nav_menu($nav_menu_selected_id)) {
    $edit_markup = nxt_get_nav_menu_to_edit($nav_menu_selected_id);
}
function nxt_nav_menu_max_depth($classes)
{
    global $_nxt_nav_menu_max_depth;
    return "{$classes} menu-max-depth-{$_nxt_nav_menu_max_depth}";
}
add_filter('admin_body_class', 'nxt_nav_menu_max_depth');
nxt_nav_menu_setup();
nxt_initial_nav_menu_meta_boxes();
if (!current_theme_supports('menus') && !nxt_get_nav_menus()) {
    $messages[] = '<div id="message" class="updated"><p>' . __('The current theme does not natively support menus, but you can use the &#8220;Custom Menu&#8221; widget to add any menus you create here to the theme&#8217;s sidebar.') . '</p></div>';
}
get_current_screen()->add_help_tab(array('id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('This feature allows you to use a custom menu in place of your theme&#8217;s default menus.') . '</p>' . '<p>' . __('Custom menus may contain links to pages, categories, custom links or other content types (use the Screen Options tab to decide which ones to show on the screen). You can specify a different navigation label for a menu item as well as other attributes. You can create multiple menus. If your theme includes more than one menu, you can choose which custom menu to associate with each. You can also use custom menus in conjunction with the Custom Menus widget.') . '</p>' . '<p>' . __('If your theme does not support the custom menus feature yet (the default themes, Twenty Eleven and Twenty Ten, do), you can learn about adding this support by following the Documentation link to the side.') . '</p>'));
get_current_screen()->add_help_tab(array('id' => 'create-menus', 'title' => __('Create Menus'), 'content' => '<p>' . __('To create a new custom menu, click on the + tab, give the menu a name, and click Create Menu. Next, add menu items from the appropriate boxes. You&#8217;ll be able to edit the information for each menu item, and can drag and drop to put them in order. You can also drag a menu item a little to the right to make it a submenu, to create menus with hierarchy. Drop the item into its new nested placement when the dotted rectangle target shifts over, also a little to the right. Don&#8217;t forget to click Save when you&#8217;re finished.') . '</p>'));
get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.nxtclass.org/Appearance_Menus_Screen" target="_blank">Documentation on Menus</a>') . '</p>' . '<p>' . __('<a href="http://nxtclass.org/support/" target="_blank">Support Forums</a>') . '</p>');
// Get the admin header
require_once './admin-header.php';
?>
<div class="wrap">
	<?php 
screen_icon();
?>
	<h2><?php 
esc_html_e('Menus');
?>
コード例 #3
0
ファイル: export.php プロジェクト: nxtclass/NXTClass
 /**
  * Ouput all navigation menu terms
  *
  * @since 3.1.0
  */
 function wxr_nav_menu_terms()
 {
     $nav_menus = nxt_get_nav_menus();
     if (empty($nav_menus) || !is_array($nav_menus)) {
         return;
     }
     foreach ($nav_menus as $menu) {
         echo "\t<nxt:term><nxt:term_id>{$menu->term_id}</nxt:term_id><nxt:term_taxonomy>nav_menu</nxt:term_taxonomy><nxt:term_slug>{$menu->slug}</nxt:term_slug>";
         wxr_term_name($menu);
         echo "</nxt:term>\n";
     }
 }
コード例 #4
0
    function admin_main($data)
    {
        if (!$data) {
            $data = array();
        }
        ?>
		<div class='level-operation' id='main-menu'>
			<h2 class='sidebar-name'><?php 
        _e('Menu', 'membership');
        ?>
<span><a href='#remove' id='remove-menu' class='removelink' title='<?php 
        _e("Remove Menu from this rules area.", 'membership');
        ?>
'><?php 
        _e('Remove', 'membership');
        ?>
</a></span></h2>
			<div class='inner-operation'>
				<p><?php 
        _e('Select the Menu items to be covered by this rule by checking the box next to the relevant menu labels.', 'membership');
        ?>
</p>
				<?php 
        $navs = nxt_get_nav_menus(array('orderby' => 'name'));
        if (!empty($navs)) {
            ?>
						<table cellspacing="0" class="widefat fixed">
							<thead>
							<tr>
								<th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th>
								<th style="" class="manage-column column-name" id="name" scope="col"><?php 
            _e('Menu / Item title', 'membership');
            ?>
</th>
								</tr>
							</thead>

							<tfoot>
							<tr>
								<th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th>
								<th style="" class="manage-column column-name" id="name" scope="col"><?php 
            _e('Menu / Item title', 'membership');
            ?>
</th>
								</tr>
							</tfoot>

							<tbody>
						<?php 
            foreach ($navs as $key => $nav) {
                ?>
							<tr valign="middle" class="alternate" id="menu-<?php 
                echo $nav->term_id;
                ?>
-0">
								<td class="column-name" colspan='2'>
									<strong><?php 
                echo __('MENU', 'membership') . " - " . esc_html($nav->name);
                ?>
</strong>
								</td>
						    </tr>
							<?php 
                $items = nxt_get_nav_menu_items($nav->term_id);
                if (!empty($items)) {
                    foreach ($items as $ikey => $item) {
                        ?>
									<tr valign="middle" class="alternate" id="menu-<?php 
                        //echo $nav->term_id . '-';
                        echo $item->ID;
                        ?>
">
										<th class="check-column" scope="row">
											<input type="checkbox" value="<?php 
                        //echo $nav->term_id . '-';
                        echo $item->ID;
                        ?>
" name="menu[]" <?php 
                        if (in_array($item->ID, $data)) {
                            echo 'checked="checked"';
                        }
                        ?>
>
										</th>
										<td class="column-name">

											<strong>&nbsp;&#8211;&nbsp;<?php 
                        if ($item->menu_item_parent != 0) {
                            echo "&#8211;&nbsp;";
                        }
                        echo esc_html($item->title);
                        ?>
</strong>
										</td>
								    </tr>
									<?php 
                    }
                }
            }
            ?>
							</tbody>
						</table>
						<?php 
        }
        ?>
			</div>
		</div>
		<?php 
    }
コード例 #5
0
ファイル: nav-menu.php プロジェクト: nxtclass/NXTClass
/**
 * Displays a metabox for the nav menu theme locations.
 *
 * @since 3.0.0
 */
function nxt_nav_menu_locations_meta_box()
{
    global $nav_menu_selected_id;
    if (!current_theme_supports('menus')) {
        // We must only support widgets. Leave a message and bail.
        echo '<p class="howto">' . __('The current theme does not natively support menus, but you can use the &#8220;Custom Menu&#8221; widget to add any menus you create here to the theme&#8217;s sidebar.') . '</p>';
        return;
    }
    $locations = get_registered_nav_menus();
    $menus = nxt_get_nav_menus();
    $menu_locations = get_nav_menu_locations();
    $num_locations = count(array_keys($locations));
    echo '<p class="howto">' . sprintf(_n('Your theme supports %s menu. Select which menu you would like to use.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations), number_format_i18n($num_locations)) . '</p>';
    foreach ($locations as $location => $description) {
        ?>
		<p>
			<label class="howto" for="locations-<?php 
        echo $location;
        ?>
">
				<span><?php 
        echo $description;
        ?>
</span>
				<select name="menu-locations[<?php 
        echo $location;
        ?>
]" id="locations-<?php 
        echo $location;
        ?>
">
					<option value="0"></option>
					<?php 
        foreach ($menus as $menu) {
            ?>
					<option<?php 
            selected(isset($menu_locations[$location]) && $menu_locations[$location] == $menu->term_id);
            ?>
						value="<?php 
            echo $menu->term_id;
            ?>
"><?php 
            $truncated_name = nxt_html_excerpt($menu->name, 40);
            echo $truncated_name == $menu->name ? $menu->name : trim($truncated_name) . '&hellip;';
            ?>
</option>
					<?php 
        }
        ?>
				</select>
			</label>
		</p>
	<?php 
    }
    ?>
	<p class="button-controls">
		<img class="waiting" src="<?php 
    echo esc_url(admin_url('images/nxtspin_light.gif'));
    ?>
" alt="" />
		<?php 
    submit_button(__('Save'), 'primary', 'nav-menu-locations', false, disabled($nav_menu_selected_id, 0, false));
    ?>
	</p>
	<?php 
}