当前位置: 首页>>代码示例>>PHP>>正文


PHP wp_get_nav_menu_items函数代码示例

本文整理汇总了PHP中wp_get_nav_menu_items函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_nav_menu_items函数的具体用法?PHP wp_get_nav_menu_items怎么用?PHP wp_get_nav_menu_items使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wp_get_nav_menu_items函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: widget

 function widget($args, $instance)
 {
     ob_start();
     extract($args);
     $title = !empty($instance['title']) ? esc_attr($instance['title']) : __('Custom Menu', 'zn_framework');
     $title = apply_filters('widget_title', $title, $instance, $this->id_base);
     $menu = isset($instance['menu']) ? esc_attr($instance['menu']) : '';
     $style = isset($instance['style']) ? esc_attr($instance['style']) : '';
     $columns = isset($instance['columns']) ? esc_attr($instance['columns']) : '';
     if (empty($menu)) {
         echo 'Please edit the widget and select at least one menu';
         return;
     }
     echo $before_widget;
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     $menu_items = wp_get_nav_menu_items($menu);
     echo '<ul class="menu-' . $menu . ' ' . $style . ' clearfix ">';
     //row
     foreach ((array) $menu_items as $key => $menu_item) {
         $title = $menu_item->title;
         $url = $menu_item->url;
         echo '<li class="' . $columns . '"><a href="' . $url . '">' . $title . '</a></li>';
     }
     echo '</ul>';
     echo $after_widget;
     // Reset the global $the_post as this query will have stomped on it
     wp_reset_postdata();
 }
开发者ID:fjbeteiligung,项目名称:development,代码行数:30,代码来源:custom_menu.php

示例2: widget

 /**
  * Echo the widget content.
  *
  * @since 1.0.0
  *
  * @param array $args     Display arguments including before_title, after_title,
  *                        before_widget, and after_widget.
  * @param array $instance The settings for the particular instance of the widget.
  */
 function widget($args, $instance)
 {
     $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
     echo $args['before_widget'];
     // Render title.
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     $nav_menu_locations = get_nav_menu_locations();
     $menu_id = 0;
     if (isset($nav_menu_locations['social']) && absint($nav_menu_locations['social']) > 0) {
         $menu_id = absint($nav_menu_locations['social']);
     }
     if ($menu_id > 0) {
         $menu_items = wp_get_nav_menu_items($menu_id);
         if (!empty($menu_items)) {
             echo '<ul class="size-medium">';
             foreach ($menu_items as $m_key => $m) {
                 echo '<li>';
                 echo '<a href="' . esc_url($m->url) . '" target="_blank">';
                 echo '<span class="title screen-reader-text">' . esc_attr($m->title) . '</span>';
                 echo '</a>';
                 echo '</li>';
             }
             echo '</ul>';
         }
     }
     echo $args['after_widget'];
 }
开发者ID:LSYanJun,项目名称:wordpress,代码行数:38,代码来源:widgets.php

示例3: clear_menu_from_old_woo_pages

function clear_menu_from_old_woo_pages()
{
    $locations = get_nav_menu_locations();
    $logout = get_page_by_path('my-account/logout');
    $parent = get_page_by_path('my-account');
    $permalink = get_option('permalink_structure');
    $pages_deleted = array(get_option('woocommerce_pay_page_id'), get_option('woocommerce_thanks_page_id'), get_option('woocommerce_view_order_page_id'), get_option('woocommerce_view_order_page_id'), get_option('woocommerce_change_password_page_id'), get_option('woocommerce_edit_address_page_id'), get_option('woocommerce_lost_password_page_id'));
    foreach ((array) $locations as $name => $menu_ID) {
        $items = wp_get_nav_menu_items($menu_ID);
        foreach ((array) $items as $item) {
            if (!is_null($logout) && !is_null($parent) && $item->object_id == $logout->ID) {
                update_post_meta($item->ID, '_menu_item_object', 'custom');
                update_post_meta($item->ID, '_menu_item_type', 'custom');
                if ($permalink == '') {
                    $new_url = get_permalink($parent->ID) . '&customer-logout';
                } else {
                    wp_update_post(array('ID' => $logout->ID, 'post_name' => 'customer-logout'));
                    $new_url = get_permalink($logout->ID);
                }
                update_post_meta($item->ID, '_menu_item_url', $new_url);
                wp_update_post(array('ID' => $item->ID, 'post_title' => $logout->post_title));
            }
            foreach ($pages_deleted as $page) {
                if ($page && $item->object_id == $page && $item->object == 'page') {
                    wp_delete_post($item->ID);
                }
            }
        }
    }
}
开发者ID:jayeshnair,项目名称:ctp,代码行数:30,代码来源:woocommerce.php

示例4: getMenu

 public function getMenu($name)
 {
     if (!array_key_exists($name, $this->menus)) {
         $this->load();
         if (!($menu = wp_get_nav_menu_object($name))) {
             throw new \Exception('Erreur menu introuvable');
         }
         $items = wp_get_nav_menu_items($menu->term_id);
         $all_items_inline = array();
         $root_items = array();
         foreach ($items as $item) {
             $objectItem = new MenuItem($item);
             if ($item->menu_item_parent != 0) {
                 if (!isset($all_items_inline[$item->menu_item_parent])) {
                     throw new \Exception('Erreur parent introuvable');
                 }
                 $objectItem->setParent($all_items_inline[$item->menu_item_parent]);
                 $objectItem->getParent()->addChild($objectItem);
             }
             $all_items_inline[$objectItem->getId()] = $objectItem;
             if ($objectItem->getParent() === null) {
                 $root_items[] = $objectItem;
             }
             $objectItem->setCss(get_post_meta($item->ID, '_menu_item_classes', true));
         }
         $this->menus[$name] = new Menu($menu->term_id, $root_items);
     }
     return $this->menus[$name];
 }
开发者ID:cmoncy,项目名称:WordpressBundle,代码行数:29,代码来源:WordpressLoader.php

示例5: set_menu

 function set_menu()
 {
     $args = array("order" => "ASC", "orderby" => "menu_order", "post_type" => "nav_menu_item", "post_status" => "publish", "output" => ARRAY_A, "output_key" => "menu_order", "nopaging" => true, "update_post_term_cache" => false);
     $menu_items = wp_get_nav_menu_items($this->get_menu_name(), $args);
     $mns = array();
     $sorted_menu_items = $menu_items_with_children = array();
     foreach ((array) $menu_items as $menu_item) {
         $sorted_menu_items[$menu_item->menu_order] = $menu_item;
         if ($menu_item->menu_item_parent) {
             $menu_items_with_children[$menu_item->menu_item_parent] = true;
         }
         if (!$menu_item->menu_item_parent) {
             $mns[$menu_item->menu_order] = new JSON_API_Application_Navigation_Items($menu_item);
         }
     }
     // Add the menu-item-has-children class where applicable
     if ($menu_items_with_children) {
         foreach ($sorted_menu_items as &$menu_item) {
             if (isset($menu_items_with_children[$menu_item->ID])) {
                 $menu_item->classes[] = 'menu-item-has-children';
             }
         }
     }
     unset($menu_items, $menu_item);
     $this->create_tree($sorted_menu_items);
 }
开发者ID:benshez,项目名称:DreamWeddingCeremonies,代码行数:26,代码来源:navigation.php

示例6: after_validate_fields

 function after_validate_fields($instance = '')
 {
     if (isset($instance['menu_id']) && isset($instance['menu_label']) && !empty($instance['menu_id']) && !empty($instance['menu_label'])) {
         $key = sanitize_key($instance['menu_label']);
         if (isset($instance['custom_container_id']) && !empty($instance['custom_container_id'])) {
             $key = $instance['custom_container_id'];
         } else {
             $instance['custom_container_id'] = $key;
         }
         $menu_link = '#HOME_URL#' . $key;
         $is_link = false;
         $menu_item_id = $menu_item_position = 0;
         $menu_items = wp_get_nav_menu_items($instance['menu_id']);
         foreach ($menu_items as $menu_item) {
             if ($menu_item->url == $menu_link) {
                 $menu_item_id = $menu_item->ID;
                 $menu_item_position = $menu_item->menu_order;
                 break;
             }
         }
         wp_update_nav_menu_item($instance['menu_id'], $menu_item_id, array('menu-item-title' => $instance['menu_label'], 'menu-item-classes' => 'internal', 'menu-item-url' => $menu_link, 'menu-item-position' => $menu_item_position, 'menu-item-status' => 'publish'));
         update_option('menu_check', true);
     }
     return $instance;
 }
开发者ID:rinodung,项目名称:myfreetheme,代码行数:25,代码来源:row-options.php

示例7: __construct

 public function __construct($menu_term_slug)
 {
     parent::__construct();
     $menu = wp_get_nav_menu_object($menu_term_slug);
     if (!empty($menu)) {
         $this->menu = $menu;
         $nav_menu_items = wp_get_nav_menu_items($this->menu->term_id);
         cfd_tmp_dbg('nav_menu_items_raw.txt', $nav_menu_items, 'print');
         foreach ($nav_menu_items as $item) {
             $menu_item = wp_setup_nav_menu_item($item);
             $menu_item->metadata = get_metadata('post', $item->ID);
             foreach ($menu_item->metadata as $key => &$value) {
                 $value[0] = maybe_unserialize($value[0]);
             }
             if ($menu_item->type == 'post_type') {
                 $menu_item->parent = get_post($menu_item->metadata['_menu_item_object_id'][0]);
             } elseif ($menu_item->type == 'taxonomy' && (!property_exists($menu, 'object') || $menu->object != 'custom')) {
                 $menu_item->term = get_term($menu_item->metadata['_menu_item_object_id'][0], $menu_item->metadata['_menu_item_object'][0]);
             }
             $this->items[] = $menu_item;
         }
     } else {
         throw new Exception(__('Invalid menu id', 'cf-deploy') . ': ' . esc_attr($menu_term_slug));
     }
 }
开发者ID:niko-lgdcom,项目名称:wp-install,代码行数:25,代码来源:menu.class.php

示例8: 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'));
         }
     }
 }
开发者ID:m-godefroid76,项目名称:devrestofactory,代码行数:25,代码来源:theme-functions.php

示例9: bogo_admin_enqueue_scripts

function bogo_admin_enqueue_scripts($hook_suffix)
{
    if (false !== strpos($hook_suffix, 'bogo-tools') || 'widgets.php' == $hook_suffix || 'user-edit.php' == $hook_suffix) {
        wp_enqueue_style('bogo-admin', plugins_url('admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME), array(), BOGO_VERSION, 'all');
        return;
    }
    if ('nav-menus.php' == $hook_suffix) {
        $nav_menu_id = absint(get_user_option('nav_menu_recently_edited'));
        $nav_menu_items = wp_get_nav_menu_items($nav_menu_id);
        $locales = array();
        foreach ((array) $nav_menu_items as $item) {
            $locales[$item->db_id] = $item->bogo_locales;
        }
        $prefix = 'menu-item-bogo-locale';
        wp_enqueue_script('bogo-admin', plugins_url('admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME), array('jquery'), BOGO_VERSION, true);
        wp_localize_script('bogo-admin', '_bogo', array('availableLanguages' => bogo_available_languages('orderby=value'), 'locales' => $locales, 'selectorLegend' => __('Displayed on pages in', 'bogo'), 'cbPrefix' => $prefix));
        wp_enqueue_style('bogo-admin', plugins_url('admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME), array(), BOGO_VERSION, 'all');
        return;
    }
    if ('options-general.php' == $hook_suffix) {
        wp_enqueue_script('bogo-admin', plugins_url('admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME), array('jquery'), BOGO_VERSION, true);
        wp_localize_script('bogo-admin', '_bogo', array('defaultLocale' => bogo_get_default_locale()));
        return;
    }
}
开发者ID:karthikakamalanathan,项目名称:wp-cookieLawInfo,代码行数:25,代码来源:admin.php

示例10: getPathFromNavMenu

 public function getPathFromNavMenu($postId)
 {
     $path = array();
     if (is_page()) {
         if ($this->menuItems === null) {
             $locations = get_nav_menu_locations();
             if (isset($locations['prime_nav_menu'])) {
                 $this->menuItems = wp_get_nav_menu_items($locations['prime_nav_menu']);
             } else {
                 $this->menuItems = false;
             }
         }
         if ($this->menuItems) {
             foreach ($this->menuItems as $menuItem) {
                 if ($menuItem->object_id == $postId) {
                     $node = $this->getNode($menuItem);
                     if ($node) {
                         $path[] = $node;
                     }
                     if ($menuItem->menu_item_parent) {
                         $parentNodes = $this->getParentNodes($menuItem->menu_item_parent);
                         $path = array_merge($path, $parentNodes);
                     }
                     break;
                 }
             }
         }
     }
     $path = array_reverse($path);
     return $path;
 }
开发者ID:nikolaskarica,项目名称:bds-alliance,代码行数:31,代码来源:breadcrumb.php

示例11: addClass

 public function addClass($classes, $item)
 {
     if (!($this->postType = $this->getPostType())) {
         return $classes;
     }
     if ($this->isActive($item)) {
         $classes[] = 'current-menu-item';
     }
     /**
      * Parents & ancestors
      */
     if (count(array_intersect(array('current-menu-item', 'current-menu-parent', 'current-menu-ancestor'), $classes)) == 0) {
         $navMenu = wp_get_post_terms($item->ID, 'nav_menu');
         if (count($navMenu) > 0) {
             if (isset($this->_cache[$navMenu[0]->term_id])) {
                 $menuItems = $this->_cache[$navMenu[0]->term_id];
             } else {
                 $menuItems = wp_get_nav_menu_items($navMenu[0]->term_id);
                 $this->_cache[$navMenu[0]->term_id] = $menuItems;
             }
             foreach ($menuItems as $menuItem) {
                 if ($this->isActive($menuItem)) {
                     if ($depth = $this->findActiveDepth($menuItem, $item, $menuItems)) {
                         if ($depth == 1) {
                             $classes[] = 'current-menu-parent';
                         } elseif ($depth > 1) {
                             $classes[] = 'current-menu-ancestor';
                         }
                     }
                 }
             }
         }
     }
     return $classes;
 }
开发者ID:trendwerk,项目名称:post-type-menu-highlight,代码行数:35,代码来源:Highlight.php

示例12: menu_endpoint

function menu_endpoint($data)
{
    $args = array('order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true, 'update_post_term_cache' => false);
    $menu = wp_get_nav_menu_items($data['id'], $args);
    $fallback_menu = wp_get_nav_menu_items('2', $args);
    $menu = json_decode(json_encode($menu), true);
    $fallback_menu = json_decode(json_encode($fallback_menu), true);
    if ($menu != false) {
        $menu = $menu;
    } else {
        $menu = $fallback_menu;
    }
    for ($i = 0; $i < sizeof($menu); $i++) {
        unset($menu[$i]['post_password']);
        unset($menu[$i]['post_name']);
        unset($menu[$i]['to_ping']);
        unset($menu[$i]['pinged']);
        unset($menu[$i]['post_modified']);
        unset($menu[$i]['post_modified_gmt']);
        unset($menu[$i]['post_content_filtered']);
        unset($menu[$i]['post_parent']);
        unset($menu[$i]['post_mime_type']);
        unset($menu[$i]['comment_count']);
        unset($menu[$i]['filter']);
        unset($menu[$i]['object']);
        unset($menu[$i]['type']);
        unset($menu[$i]['post_date']);
        unset($menu[$i]['post_date_gmt']);
        $menu[$i]['template'] = split('.php', get_page_template_slug($menu[$i]['object_id']))[0];
    }
    //if the id would return nothing - return the default menu
    return $menu;
}
开发者ID:stagfoo,项目名称:Headless-Bankend,代码行数:33,代码来源:menu.php

示例13: ut_prepare_front_query

 function ut_prepare_front_query()
 {
     /* needed variables and arrays */
     $ut_query_pages = array();
     /* check if primary navigation has been created and set */
     if (has_nav_menu('primary')) {
         /* get primary navigation ID */
         $ut_theme_locations = get_nav_menu_locations();
         $ut_menu_objects = get_term($ut_theme_locations['primary'], 'nav_menu');
         $ut_menu_id = $ut_menu_objects->term_id;
         /* now we get all menu items from primary navigation  */
         $menu_args = array('orderby' => 'menu_order');
         $ut_menu_items = wp_get_nav_menu_items($ut_menu_id, $menu_args);
         /* create an array of page ID's for query_posts() */
         foreach ((array) $ut_menu_items as $key => $ut_menu_item) {
             $blog_page_id = get_option('page_for_posts');
             $frontpage_id = get_option('page_on_front');
             if ($ut_menu_item->menutype == 'section' && $blog_page_id != $ut_menu_item->object_id && $frontpage_id != $ut_menu_item->object_id) {
                 $ut_query_pages[] = $ut_menu_item->object_id;
                 /* get child pages */
                 $children = ut_get_posts_children_ids($ut_menu_item->object_id);
                 $ut_query_pages = array_merge($ut_query_pages, $children);
             }
         }
         /* return query arguements */
         if (!empty($ut_query_pages)) {
             /* query args for main query  */
             $pagequery = array('posts_per_page' => count($ut_query_pages), 'post_type' => 'page', 'post__in' => $ut_query_pages, 'orderby' => 'post__in');
             return $pagequery;
         } else {
             /* return empty arguments */
             return array();
         }
     }
 }
开发者ID:amptdesign,项目名称:ampt-2016,代码行数:35,代码来源:ut-prepare-front-page.php

示例14: add_custom_icons_var_to_scss

 /**
  * Create a new variable containing the IDs and icons of menu items to be used by the SCSS file
  *
  * @param array $vars
  * @param string $location
  * @param string $theme
  * @param int $menu_id
  * @return string - all custom SCSS vars
  * @since 1.0
  */
 public function add_custom_icons_var_to_scss($vars, $location, $theme, $menu_id)
 {
     $menu_items = wp_get_nav_menu_items($menu_id);
     $custom_vars = array();
     if (is_array($menu_items)) {
         foreach ($menu_items as $menu_order => $item) {
             if ($settings = get_post_meta($item->ID, "_megamenu", true)) {
                 if (isset($settings['icon']) && $settings['icon'] == 'custom' && isset($settings['custom_icon']['id']) && intval($settings['custom_icon']['id']) > 0) {
                     $id = $settings['custom_icon']['id'];
                     $width = $settings['custom_icon']['width'];
                     $height = $settings['custom_icon']['height'];
                     $vertical_align = $settings['custom_icon']['vertical_align'];
                     $styles = array('id' => $item->ID, 'custom_icon_url' => "'" . apply_filters("megamenu_custom_icon_url", $this->get_resized_image_url($id, $width, $height)) . "'", 'custom_icon_width' => $width . 'px', 'custom_icon_height' => $height . 'px', 'custom_icon_2x_url' => "'" . apply_filters("megamenu_custom_icon_url", $this->get_resized_image_url($id, $width * 2, $height * 2)) . "'", 'custom_icon_2x_width' => $width * 2 . 'px', 'custom_icon_2x_height' => $height * 2 . 'px', 'custom_icon_vertical_align' => $vertical_align);
                     $custom_vars[$item->ID] = $styles;
                 }
             }
         }
     }
     //$custom_icons:(
     // (123, red, 150px),
     // (456, green, null),
     // (789, blue, 90%),());
     if (count($custom_vars)) {
         $list = "(";
         foreach ($custom_vars as $id => $vals) {
             $list .= "(" . implode(",", $vals) . "),";
         }
         // Always add an empty list item to meke sure there are always at least 2 items in the list
         // Lists with a single item are not treated the same way by SASS
         $list .= "());";
         $vars['custom_icons'] = $list;
     }
     return $vars;
 }
开发者ID:pjenkinson,项目名称:knowsley_college_wp,代码行数:44,代码来源:custom.php

示例15: getItems

 protected function getItems($menu)
 {
     $items = [];
     // Get all items for the current menu
     if ($menu && !is_wp_error($menu)) {
         $menu_items = wp_get_nav_menu_items($menu->term_id);
     }
     // Check if the menu is not empty
     if (!$menu_items) {
         $items[] = ['name' => '', 'label' => 'No items', 'disabled' => true];
     } else {
         $walker = new AssignmentsWalker();
         $new_menu_items = [];
         foreach ($menu_items as $new_menu_item) {
             $new_menu_item->id = $new_menu_item->ID;
             $new_menu_item->parent_id = empty($new_menu_item->menu_item_parent) ? get_post_meta($new_menu_item->ID, '_menu_item_menu_item_parent', true) : $new_menu_item->menu_item_parent;
             $new_menu_items[] = $new_menu_item;
         }
         $menu_items = $walker->walk($new_menu_items, 0);
         foreach ($menu_items as $menu_item) {
             $items[] = ['name' => $menu_item->ID, 'label' => $menu_item->level > 0 ? str_repeat('—', $menu_item->level) . ' ' . $menu_item->title : $menu_item->title, 'disabled' => false];
         }
     }
     return apply_filters('g5_assignments_' . $menu->slug . '_menu_list_items', $items, $menu->slug, $this->type);
 }
开发者ID:nmsde,项目名称:gantry5,代码行数:25,代码来源:AssignmentsMenu.php


注:本文中的wp_get_nav_menu_items函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。