本文整理汇总了PHP中wp_get_nav_menu_object函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_nav_menu_object函数的具体用法?PHP wp_get_nav_menu_object怎么用?PHP wp_get_nav_menu_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_get_nav_menu_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: widget
function widget($args, $instance)
{
extract($args);
// Get menu
if (!isset($instance['speed'])) {
$instance['speed'] = 'slow';
}
$widget_options = wp_parse_args($instance, $this->defaults);
extract($widget_options, EXTR_SKIP);
$nav_menu = wp_get_nav_menu_object($instance['nav_menu']);
if (!$nav_menu) {
return;
}
$instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
$classMenu = $instance['classMenu'] != '' ? $instance['classMenu'] : 'menu';
echo $args['before_widget'];
if (!empty($instance['title'])) {
echo $args['before_title'] . $instance['title'] . $args['after_title'];
}
?>
<div class="dcjq-accordion" id="<?php
echo $this->id . '-item';
?>
">
<?php
wp_nav_menu(array('fallback_cb' => '', 'menu' => $nav_menu, 'container' => false, 'menu_class' => $classMenu));
?>
</div>
<?php
echo $args['after_widget'];
}
示例2: theme_get_menu
function theme_get_menu($args = '')
{
$args = wp_parse_args($args, array('source' => 'Pages', 'depth' => 0, 'menu' => null, 'class' => ''));
$source =& $args['source'];
$menu =& $args['menu'];
$class =& $args['class'];
if ($menu != null && is_string($menu)) {
// theme location
$location = theme_get_array_value(get_nav_menu_locations(), $menu);
if ($location) {
$menu = wp_get_nav_menu_object($location);
if ($menu) {
$source = 'Custom Menu';
//Jordi
//$class = implode(' ', array($class, 'menu-' . $menu->term_id));
$class = implode(' ', array($class, 'menu-' . $menu->term_id, 'nav navbar-right'));
}
}
}
if ($source == 'Custom Menu' && $menu != null) {
return theme_get_list_menu($args);
}
if ($source == 'Pages') {
return theme_get_list_pages(array_merge(array('sort_column' => 'menu_order, post_title'), $args));
}
if ($source == 'Categories') {
return theme_get_list_categories(array_merge(array('title_li' => false), $args));
}
}
示例3: widget
/**
* Outputs the content for the current Custom Menu widget instance.
*
* @since 3.0.0
* @access public
*
* @param array $args Display arguments including 'before_title', 'after_title',
* 'before_widget', and 'after_widget'.
* @param array $instance Settings for the current Custom Menu widget instance.
*/
public function widget($args, $instance)
{
// Get menu
$nav_menu = !empty($instance['nav_menu']) ? wp_get_nav_menu_object($instance['nav_menu']) : false;
if (!$nav_menu) {
return;
}
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$instance['title'] = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
echo $args['before_widget'];
if (!empty($instance['title'])) {
echo $args['before_title'] . $instance['title'] . $args['after_title'];
}
$nav_menu_args = array('fallback_cb' => '', 'menu' => $nav_menu);
/**
* Filter the arguments for the Custom Menu widget.
*
* @since 4.2.0
* @since 4.4.0 Added the `$instance` parameter.
*
* @param array $nav_menu_args {
* An array of arguments passed to wp_nav_menu() to retrieve a custom menu.
*
* @type callable|bool $fallback_cb Callback to fire if the menu doesn't exist. Default empty.
* @type mixed $menu Menu ID, slug, or name.
* }
* @param stdClass $nav_menu Nav menu object for the current menu.
* @param array $args Display arguments for the current widget.
* @param array $instance Array of settings for the current widget.
*/
wp_nav_menu(apply_filters('widget_nav_menu_args', $nav_menu_args, $nav_menu, $args, $instance));
echo $args['after_widget'];
}
示例4: widget
function widget($args, $instance)
{
global $post;
$cache = wp_cache_get('widget_progressive_menu', 'widget');
if (!is_array($cache)) {
$cache = array();
}
if (!isset($args['widget_id'])) {
$args['widget_id'] = $this->id;
}
if (isset($cache[$args['widget_id']])) {
echo $cache[$args['widget_id']];
return;
}
$nav_menu = !empty($instance['nav_menu']) ? wp_get_nav_menu_object($instance['nav_menu']) : false;
if (!$nav_menu) {
return;
}
ob_start();
extract($args);
echo $before_widget;
if (!empty($instance['title'])) {
$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
echo $before_title . esc_html($title) . $after_title;
}
echo '<nav>';
wp_nav_menu(array('fallback_cb' => '', 'container' => false, 'menu' => $nav_menu, 'menu_class' => 'theme-menu', 'depth' => 2, 'walker' => new progressive_menu_widget_walker_nav_menu()));
echo '</nav>';
?>
<?php
echo $after_widget;
$cache[$args['widget_id']] = ob_get_flush();
wp_cache_set('widget_progressive_menu', $cache, 'widget');
}
示例5: get_args
/**
* Generate arguments depends on location and menu
*/
function get_args($args)
{
$this->profile_id = WR_Megamenu_Helpers_Functions::get_profile_by_location($args['theme_location']);
if ($this->profile_id) {
// Show only once in one location
if ($this->echo == $args['theme_location']) {
$args['echo'] = FALSE;
}
$this->echo = $args['theme_location'];
$args['profile_id'] = $this->profile_id;
$this->settings = WR_Megamenu_Helpers_Builder::get_megamenu_data($this->profile_id);
// load assets for a profile
$this->load_profile_assets();
$menu_type = $this->settings['menu_type'];
$location = $this->settings['location'];
// Get the nav menu based on the requested menu
$menu = wp_get_nav_menu_object($menu_type);
$locations = get_nav_menu_locations();
if (!$menu && $location && isset($locations[$location])) {
// Get the nav menu based on the theme_location
$menu = wp_get_nav_menu_object($locations[$location]);
}
if ($menu && $menu->term_id == $menu_type && isset($locations[$location])) {
$args['menu_type'] = $menu_type;
$args['theme_location'] = $location;
$helper = new WR_Megamenu_Helpers_Frontend();
return $helper->get_args($args);
} else {
return $args;
}
} else {
return $args;
}
return $args;
}
示例6: register
public static function register()
{
register_nav_menu(self::$location, self::$description);
if (!wp_get_nav_menu_object(self::$description)) {
self::setup();
}
}
示例7: theme_get_menu
function theme_get_menu($args = '')
{
$args = apply_filters('wp_nav_menu_args', $args);
$nav_menu = apply_filters('pre_wp_nav_menu', null, $args);
if (null !== $nav_menu) {
return $nav_menu;
}
$args = wp_parse_args($args, array('source' => 'Pages', 'depth' => 0, 'menu' => null, 'class' => ''));
$source =& $args['source'];
$menu =& $args['menu'];
$class =& $args['class'];
if ($menu != null && is_string($menu)) {
// theme location
$location = theme_get_array_value(get_nav_menu_locations(), $menu);
if ($location) {
$menu = wp_get_nav_menu_object($location);
if ($menu) {
$source = 'Custom Menu';
$class = implode(' ', array($class, 'menu-' . $menu->term_id));
}
}
}
if ($source == 'Custom Menu' && $menu != null) {
$nav_menu = theme_get_list_menu($args);
} elseif ($source == 'Pages') {
$nav_menu = theme_get_list_pages(array_merge(array('sort_column' => 'menu_order, post_title'), $args));
} elseif ($source == 'Categories') {
$nav_menu = theme_get_list_categories(array_merge(array('title_li' => false), $args));
}
return apply_filters('wp_nav_menu', $nav_menu, $args);
}
示例8: wptouch_migrate_modded_menu
function wptouch_migrate_modded_menu()
{
$menu_name = 'WPtouch - Recovered Page Menu';
$menu_object = wp_get_nav_menu_object($menu_name);
if (!$menu_object) {
$menu_id = wp_create_nav_menu($menu_name);
$pages = get_pages(array('post_status' => 'publish', 'sort_column' => 'menu_order, post_title'));
$menu_items = array();
$skipped_pages = array();
foreach ($pages as $page) {
if (wptouch_menu_is_disabled($page->ID)) {
$skipped_pages[] = $page->ID;
} elseif (!in_array($page->post_parent, $skipped_pages)) {
$parent_id = 0;
if (isset($menu_items[$page->post_parent])) {
$parent_id = $menu_items[$page->post_parent];
}
$args = array('menu-item-db-id' => 0, 'menu-item-object-id' => $page->ID, 'menu-item-object' => 'page', 'menu-item-type' => 'post_type', 'menu-item-parent-id' => $parent_id, 'menu-item-status' => 'publish');
$menu_items[$page->ID] = wp_update_nav_menu_item($menu_id, 0, $args);
$menu_icon = get_post_meta($page->ID, '_wptouch_pro_menu_item_icon', true);
if ($menu_icon) {
add_post_meta($menu_items[$page->ID], '_wptouch_pro_menu_item_icon', $menu_icon);
}
}
}
} else {
$menu_id = $menu_object->ID;
}
return $menu_id;
}
示例9: widget
/**
* widget function.
*
* @see WP_Widget
* @access public
* @param array $args
* @param array $instance
* @return void
*/
function widget( $args, $instance ) {
extract( $args );
if( !isset( $instance['title'] ) )
$instance['title'] = '';
$title = apply_filters('widget_title', $instance['title'] );
$nav_menu = isset( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : '';
include_once( YIT_THEME_ASSETS_PATH . '/lib/Walker_Nav_Menu_Div.php' );
$nav_args = array(
'menu' => $nav_menu,
'container' => 'div',
'container_class' => 'submenu',
'menu_class' => 'sub-menu clearfix',
'depth' => 3,
'walker' => new YIT_Walker_Nav_Menu_Div()
);
echo $before_widget;
echo '<ul class="yit-cm"><li>';
echo '<a href="#" class="btn-flat">'. $title .'</a>';
wp_nav_menu( $nav_args );
echo '</li></ul>';
echo $after_widget;
}
示例10: widget
public function widget($args, $instance)
{
// Get menu
$nav_menu = !empty($instance['nav_menu']) ? wp_get_nav_menu_object($instance['nav_menu']) : false;
if (!$nav_menu) {
return;
}
/** This filter is documented in wp-includes/default-widgets.php */
$instance['title'] = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
echo $args['before_widget'];
if (!empty($instance['title'])) {
echo $args['before_title'] . $instance['title'] . $args['after_title'];
}
$nav_menu_args = array('fallback_cb' => '', 'menu' => $nav_menu, 'container-class' => 'container-fluid', 'items_wrap' => '<ul id="%1$s" class="nav nav-sidebar">%3$s</ul>', 'depth' => 1);
/**
* Filter the arguments for the Custom Menu widget.
*
* @since 4.2.0
*
* @param array $nav_menu_args {
* An array of arguments passed to wp_nav_menu() to retrieve a custom menu.
*
* @type callback|bool $fallback_cb Callback to fire if the menu doesn't exist. Default empty.
* @type mixed $menu Menu ID, slug, or name.
* }
* @param stdClass $nav_menu Nav menu object for the current menu.
* @param array $args Display arguments for the current widget.
*/
wp_nav_menu(apply_filters('widget_nav_menu_args', $nav_menu_args, $nav_menu, $args));
echo $args['after_widget'];
}
示例11: expanded_nav_menu_css_class
function expanded_nav_menu_css_class($classes = array(), $item, $args)
{
$location_name = 'expanded_navigation';
static $top_level_count = 0;
//Top level menu items counter
if ($args->theme_location == $location_name) {
//Limit to this menu location only
if ($item->menu_item_parent == 0 and $top_level_count !== null) {
//Count top level menu items
$top_level_count++;
//Increment
}
if (($locations = get_nav_menu_locations()) && isset($locations[$location_name])) {
$main_nav = wp_get_nav_menu_object($locations[$location_name]);
if ($item->menu_item_parent == 0) {
$classes[] = 'col-lg-15 col-md-3 col-sm-4 ex-menu-item';
}
if ($item->menu_order == 1) {
$classes[] = 'menu-item menu-item-first';
//First menu item
}
if ($top_level_count == count_top_level_menu_items($main_nav->term_id)) {
$classes[] = 'menu-item-last';
//Last top level menu item
$top_level_count = null;
//Disable our counter, no need for it
}
}
}
return $classes;
}
示例12: start_el
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
$ul_class = 'nobulletpoints col-sm-6 hidden-xs';
if (!isset($this->current_menu)) {
$this->current_menu = wp_get_nav_menu_object($args->menu);
}
if (!isset($this->break_point)) {
$this->break_point = ceil($this->current_menu->count / 2) + 1;
}
$indent = $depth ? str_repeat("\t", $depth) : '';
$class_names = $value = '';
$classes = empty($item->classes) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
$class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args));
$class_names = ' class="' . esc_attr($class_names) . '"';
$id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args);
$id = strlen($id) ? ' id="' . esc_attr($id) . '"' : '';
if ($this->break_point == $item->menu_order) {
$output .= $indent . '</li></ul><ul class="' . $ul_class . '"><li' . $id . $value . $class_names . '>';
} else {
$output .= $indent . '<li' . $id . $value . $class_names . '>';
}
$attributes = !empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) . '"' : '';
$attributes .= !empty($item->target) ? ' target="' . esc_attr($item->target) . '"' : '';
$attributes .= !empty($item->xfn) ? ' rel="' . esc_attr($item->xfn) . '"' : '';
$attributes .= !empty($item->url) ? ' href="' . esc_attr($item->url) . '"' : '';
$item_output = $args->before;
$item_output .= '<a' . $attributes . '>';
$item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
}
示例13: van_check_menu
function van_check_menu()
{
global $VAN;
//If custom menu exist,get the ID of pages
if (($locations = get_nav_menu_locations()) && $locations['primary_navi']) {
$menu = wp_get_nav_menu_object($locations['primary_navi']);
$menu_items = wp_get_nav_menu_items($menu->term_id);
$pageID = array();
foreach ($menu_items as $item) {
if ($item->object == 'page') {
$pageID[] = $item->object_id;
}
}
query_posts(array('post_type' => 'page', 'post__in' => $pageID, 'posts_per_page' => count($pageID), 'orderby' => 'post__in'));
} else {
//If custom menu doesn't exist,check default page menu setting in theme options
//If default page menu setting exist
if (isset($VAN['pages_navi']) && $VAN['pages_navi'] != '') {
query_posts(array('post_type' => 'page', 'post__in' => $VAN['pages_navi'], 'posts_per_page' => count($VAN['pages_navi']), 'orderby' => 'menu_order', 'order' => 'ASC'));
} else {
//If default page menu setting doesn't exist
query_posts(array('post_type' => 'page', 'posts_per_page' => 6, 'orderby' => 'menu_order', 'order' => 'ASC'));
}
}
}
示例14: theme_get_menu
function theme_get_menu($args = '')
{
$args = wp_parse_args($args, array('source' => 'Pages', 'depth' => 0, 'menu' => null, 'class' => ''));
$source =& $args['source'];
$menu =& $args['menu'];
if (function_exists('get_nav_menu_locations') && $menu != null && is_string($menu)) {
// theme location
$location = theme_get_array_value(get_nav_menu_locations(), $menu);
if ($location) {
$menu = wp_get_nav_menu_object($location);
if ($menu) {
$source = 'Custom Menu';
}
}
}
if ($source == 'Custom Menu' && function_exists('wp_nav_menu') && $menu != null) {
return theme_get_list_menu($args);
}
if ($source == 'Pages') {
return theme_get_list_pages(array_merge(array('sort_column' => 'menu_order, post_title'), $args));
}
if ($source == 'Categories') {
return theme_get_list_categories(array_merge(array('title_li' => false), $args));
}
}
示例15: _402
private function _402()
{
/* Fixed double key active_plugins */
$plugins = get_option('active_plugins');
if (is_array($plugins)) {
$_plugins = array();
foreach ($plugins as $plugin) {
if (!in_array($plugin, $_plugins)) {
array_push($_plugins, $plugin);
}
}
update_option('active_plugins', $_plugins);
}
/* Create new menu - top nav */
$menu_name = 'Top Navigation';
//wp_delete_nav_menu( $menu_name );
$menu_exists = wp_get_nav_menu_object($menu_name);
if (!$menu_exists) {
$menu_id = wp_create_nav_menu($menu_name);
wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('<i class="fa fa-lock"></i> Login'), 'menu-item-url' => home_url('/?action=login'), 'menu-item-status' => 'publish'));
wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('<i class="fa fa-pencil-square-o"></i> Register'), 'menu-item-url' => home_url('/?action=register'), 'menu-item-classes' => 'two active', 'menu-item-status' => 'publish'));
$thememods = 'theme_mods_' . get_option('stylesheet', true);
$mod = get_option($thememods);
if (!isset($mod)) {
$mod = array('nav_menu_locations' => array('top_nav' => $menu_id));
} else {
$mod['nav_menu_locations']['top_nav'] = $menu_id;
}
add_option($thememods, $mod) || update_option($thememods, $mod);
}
}