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


PHP get_nav_menu_locations函数代码示例

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


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

示例1: render_main_menu

function render_main_menu()
{
    $menu_name = 'main-menu';
    // name of rendered menu
    if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
        $menu = wp_get_nav_menu_object($locations[$menu_name]);
        $menu_items = wp_get_nav_menu_items($menu->term_id);
        $menu_list = "<nav>\n";
        $menu_list .= "\t\t\t\t<ul>\n";
        foreach ((array) $menu_items as $key => $menu_item) {
            // loop menu entries
            $title = $menu_item->title;
            $classes = implode(" ", $menu_item->classes);
            $url = make_href_root_relative($menu_item->url);
            $menu_list .= "\t\t\t\t\t<li class=\"{$classes}\"><a href=\"{$url}\"><span>{$title}</span></a></li>\n";
        }
        $menu_list .= "\t\t\t\t</ul>\n";
        $menu_list .= "\t\t\t</nav>\n";
    } else {
        // try to render default menu
        $menu_list = wp_nav_menu(array('theme_location' => 'main-menu', 'container_class' => 'main-menu-container', 'container' => 'nav', 'menu_id' => 'main-menu', 'menu_class' => '', 'echo' => false));
        // $menu_list = '<!-- no list defined -->';
    }
    echo $menu_list;
}
开发者ID:hwuerz,项目名称:salzhimmel,代码行数:25,代码来源:functions.php

示例2: findMenu

 function findMenu($id = null)
 {
     $locations = get_registered_nav_menus();
     $menus = wp_get_nav_menus();
     if ($id) {
         foreach ($menus as $menu) {
             if ($id == $menu->term_id) {
                 return $menu;
             }
         }
         return null;
     }
     $menu_locations = get_nav_menu_locations();
     $return = null;
     // find current menu
     foreach ($locations as $location => $description) {
         foreach ($menus as $menu) {
             if (isset($menu_locations[$location]) && $menu_locations[$location] == $menu->term_id) {
                 $return = $menu;
                 break;
             }
         }
     }
     return $return;
 }
开发者ID:macconsultinggroup,项目名称:WordPress,代码行数:25,代码来源:custom-menu-images.php

示例3: getMenuItems

 /**
  * Return the global menu with a material design HTML structure
  */
 public static function getMenuItems($menuName)
 {
     if (($locations = get_nav_menu_locations()) && isset($locations[$menuName])) {
         $menu = wp_get_nav_menu_object($locations[$menuName]);
         return wp_get_nav_menu_items($menu->term_id);
     }
 }
开发者ID:J0hnRoger,项目名称:SLHB,代码行数:10,代码来源:NavigationModel.php

示例4: dt_get_simple_menu

function dt_get_simple_menu($opts = array())
{
    $defaults = array('menu_name' => 'top-menu', 'wrap' => '<ul class="right-top">%ITEMS%</ul>', 'item_wrap' => '<li><a href="%URL%">%TITLE%</a></li>', 'echo' => true);
    $opts = apply_filters('dt_get_simple_menu_options', wp_parse_args($opts, $defaults));
    $opts = wp_parse_args($opts, $defaults);
    if (($locations = get_nav_menu_locations()) && isset($locations[$opts['menu_name']])) {
        $menu = wp_get_nav_menu_object($locations[$opts['menu_name']]);
        if ($menu) {
            $menu_items = wp_get_nav_menu_items($menu->term_id);
            $menu_list = '';
            foreach ((array) $menu_items as $key => $menu_item) {
                $title = $menu_item->title;
                $url = $menu_item->url;
                $menu_list .= str_replace(array('%URL%', '%TITLE%'), array($url, $title), $opts['item_wrap']);
            }
            $menu_list = str_replace('%ITEMS%', $menu_list, $opts['wrap']);
            if ($opts['echo']) {
                echo $menu_list;
                return false;
            }
            return $menu_list;
        }
    }
    return null;
}
开发者ID:mnjit,项目名称:aa-global,代码行数:25,代码来源:template-helpers.php

示例5: clean_custom_menus

function clean_custom_menus()
{
    $menu_name = 'primary';
    // specify custom menu slug
    if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
        $menu = wp_get_nav_menu_object($locations[$menu_name]);
        $menu_items = wp_get_nav_menu_items($menu->term_id);
        $menu_list = '<nav>' . "\n";
        $menu_list .= '<ul class="desktop">' . "\n";
        foreach ((array) $menu_items as $key => $menu_item) {
            $title = $menu_item->title;
            $url = $menu_item->url;
            $menu_list .= '<a href="' . $url . '"><li>' . $title . '</li></a>' . "\n";
        }
        $menu_list .= '</ul>' . "\n";
        $menu_list .= "<div class='mobileNav'><div class='mobile-hamburger'><span></span></div>";
        $menu_list .= '<ul class="mobile">' . "\n";
        foreach ((array) $menu_items as $key => $menu_item) {
            $title = $menu_item->title;
            $url = $menu_item->url;
            $menu_list .= '<a href="' . $url . '"><li>' . $title . '</li></a>' . "\n";
        }
        $menu_list .= '</ul></div>' . "\n";
        $menu_list .= '</nav>' . "\n";
    } else {
        $menu_list = '<!-- no list defined -->';
    }
    echo $menu_list;
}
开发者ID:killfrog47,项目名称:warriors-of-the-month-wp,代码行数:29,代码来源:functions.php

示例6: get_settings_fields

 /**
  * Returns all the settings fields
  *
  * @return array settings fields
  */
 function get_settings_fields()
 {
     $locations = get_nav_menu_locations();
     /*
     $locations = Array
     	(
     		[location_name] = > currently_assigned_menu_id
     		[primary] => 12
     		[sidebar] => 2
     		[footer] => 0
     		
     	)
     */
     $exclude_theme_locations_opt = array();
     foreach ($locations as $key => $val) {
         $exclude_theme_locations_opt[$key] = ucfirst($key);
     }
     // Get menus
     $menus = wp_get_nav_menus();
     $exclude_menus_opt = array();
     foreach ($menus as $menu) {
         $exclude_menus_opt[$menu->term_id . "|" . $menu->slug . "|" . $menu->name] = $menu->name;
     }
     $settings_fields = array('wp_nav_menu_cache' => array(array('name' => 'exclude_theme_locations', 'label' => 'Exclude Theme Locations', 'desc' => "Check theme location you don't want to cache any menu of", 'type' => 'multicheck', 'options' => $exclude_theme_locations_opt), array('name' => 'exclude_menus', 'label' => 'Exclude Menus', 'desc' => "Check wich menu you don't want to cache.<br>You need this if you use Custom Menu widget or if you assign a menu with the call of wp_nav_menu() function in theme files.", 'type' => 'multicheck', 'options' => $exclude_menus_opt), array('name' => 'individual_url', 'label' => 'Cache for Individual URL', 'desc' => 'Enable <br><span style="color:#ff0000">You should not enable this option if you have a huge number of <strong>posts/pages</strong> on your site.<br>This option caches each menu individually <strong>for each post/page or any visited url</strong>.<br>This can result in a <strong>huge number of cached menu files</strong> on your site, which could actually resulted in a <strong>slower site</strong>.<br>It could also cross the <strong>limitation of number of files</strong> in a single directory.</span>', 'type' => 'checkbox')));
     return $settings_fields;
 }
开发者ID:onetarek,项目名称:wp-nav-menu-cache,代码行数:31,代码来源:option-page.php

示例7: 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

示例8: 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);
     $size = !empty($instance['size']) ? $instance['size'] : 'medium';
     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-' . esc_attr($size) . '">';
             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:ernilambar,项目名称:buntu,代码行数:39,代码来源:widgets.php

示例9: customize_registering

 function customize_registering($wp_customize)
 {
     global $xili_language;
     // in_nav_menu
     $locations = get_registered_nav_menus();
     $menus = wp_get_nav_menus();
     $menu_locations = get_nav_menu_locations();
     $num_locations = count(array_keys($locations));
     if ($num_locations >= 1 && count($menu_locations) >= 1) {
         $wp_customize->add_section('xili_options_section', array('title' => __('Multilingual Options ©xili', 'xili-language'), 'priority' => 300, 'description' => sprintf(_n('Your theme supports %s menu. Customize style.', 'Your theme supports %s menus. Customize style.', $num_locations, 'xili-language'), number_format_i18n($num_locations)) . "\n\n" . __('You can edit your menu content on the Menus screen in the Appearance section.')));
         $location_slugs = array_keys($locations);
         if (0 == $xili_language->has_languages_list_menu($location_slugs[0])) {
             // only test one menu during transition
             $wp_customize->add_setting('xili_language_settings[in_nav_menu]', array('default' => '', 'transport' => 'refresh', 'type' => 'option', 'capability' => $this->capability));
             $wp_customize->add_control('in_nav_menu', array('settings' => 'xili_language_settings[in_nav_menu]', 'label' => __('Append the languages', 'xili-language'), 'section' => 'xili_options_section', 'type' => 'radio', 'choices' => array('disable' => __('No languages menu-items', 'xili-language'), 'enable' => __('Show languages menu-items', 'xili-language'))));
             $wp_customize->add_setting('xili_language_settings[nav_menu_separator]', array('default' => '|', 'transport' => 'refresh', 'type' => 'option', 'capability' => $this->capability));
             $wp_customize->add_control('nav_menu_separator', array('settings' => 'xili_language_settings[nav_menu_separator]', 'label' => __('Separator before language list (Character or Entity Number or Entity Name)', 'xili-language'), 'section' => 'xili_options_section', 'type' => 'text'));
         }
         if (!current_theme_supports('custom_xili_flag')) {
             $wp_customize->add_setting($this->settings_name . '[no_flags]', array('default' => '', 'transport' => 'refresh', 'type' => 'option', 'capability' => $this->capability));
             $wp_customize->add_control('no_flags', array('settings' => $this->settings_name . '[no_flags]', 'label' => __('Hide the flags', 'xili-language'), 'section' => 'xili_options_section', 'type' => 'checkbox'));
         }
     } else {
         $wp_customize->add_section('xili_options_section', array('title' => __('Multilingual Options ©xili', 'xili-language'), 'priority' => 300, 'description' => __('None nav menus location seems active', 'xili-language')));
     }
     $wp_customize->add_setting($this->settings_name . '[linked_posts]', array('default' => '', 'transport' => 'refresh', 'type' => 'option', 'capability' => $this->capability));
     $wp_customize->add_control('linked_posts', array('settings' => $this->settings_name . '[linked_posts]', 'label' => __('Show linked posts', 'xili-language'), 'section' => 'xili_options_section', 'type' => 'checkbox'));
 }
开发者ID:ergov2015,项目名称:rideflag.dev,代码行数:28,代码来源:theme-multilingual-classes.php

示例10: 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);
}
开发者ID:spadwen,项目名称:shop.bentleigh-discount-lolly.com.au,代码行数:31,代码来源:navigation.php

示例11: _wpsc_menu_exists

function _wpsc_menu_exists($args)
{
    $args = (object) $args;
    // Get the nav menu based on the requested menu
    $menu = wp_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 = wp_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 = wp_get_nav_menus();
        foreach ($menus as $menu_maybe) {
            if ($menu_items = wp_get_nav_menu_items($menu_maybe->term_id)) {
                $menu = $menu_maybe;
                break;
            }
        }
    }
    // If the menu exists, get its items.
    if ($menu && !is_wp_error($menu) && !isset($menu_items)) {
        $menu_items = wp_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_wp_error($menu) || isset($menu_items) && empty($menu_items) && !$args->theme_location) {
        return false;
    }
    // If no fallback function was specified and the menu doesn't exists, bail.
    if (!$menu || is_wp_error($menu) || empty($menu_items)) {
        return false;
    }
    return (bool) $menu;
}
开发者ID:VanessaGarcia-Freelance,项目名称:ButtonHut,代码行数:33,代码来源:query.php

示例12: 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));
    }
}
开发者ID:JordiCruells,项目名称:mwt,代码行数:29,代码来源:navigation.php

示例13: widget

 public function widget($args, $instance)
 {
     extract($args);
     $defaults = array('title' => '', 'menu' => 'primary', 'description' => '');
     $instance = wp_parse_args((array) $instance, $defaults);
     $locations = get_nav_menu_locations();
     $title = '';
     // Create beautiful title
     if (isset($instance['title'])) {
         $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
         if (!empty($title)) {
             $title_array = explode(" ", $title);
             $title = "";
             foreach ($title_array as $tcount => $word) {
                 if ($tcount == 0) {
                     $word = "<strong>" . $word . "</strong>";
                 }
                 $title .= $word . " ";
             }
             $title = "<h2>" . $title . "</h2>";
         }
     }
     // Build menu options
     $opts = array('theme_location' => '', 'menu' => $locations[isset($instance['menu']) ? $instance['menu'] : 'primary-menu'], 'container' => '', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '', 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 'depth' => 0, 'walker' => '');
     // Create widget
     echo '<div class="widget">';
     echo $before_widget;
     echo $title;
     // Build menu
     wp_nav_menu($opts);
     echo !empty($instance['description']) ? '<p><!-- WHITESPACE --></p><ul><p>' . $instance['description'] . '</p></ul>' : '';
     echo $after_widget;
     echo '</div>';
 }
开发者ID:ashanrupasinghe,项目名称:amc-car-from-server-2015-1-14,代码行数:34,代码来源:asidemenu.php

示例14: 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

示例15: acp_skiplinks_output

function acp_skiplinks_output()
{
    check_ajax_referer('acp-sec-skiplinks', 'security');
    $hp_skiplinks = get_option('acp_skiplinks_home', false);
    if ($hp_skiplinks) {
        $menu_name = is_home() || is_front_page() ? 'skiplinks-home' : 'skiplinks';
    } else {
        $menu_name = 'skiplinks';
    }
    if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
        $menu = wp_get_nav_menu_object($locations[$menu_name]);
        $menu_items = wp_get_nav_menu_items($menu->term_id);
        $menu_side = get_option('acp_skiplinks_side', false);
        $menu_list = '<ul id="acp_skiplinks" role="navigation" class="' . $menu_side . '">';
        foreach ((array) $menu_items as $key => $menu_item) {
            $title = $menu_item->title;
            $url = $menu_item->url;
            $menu_list .= '<li><a href="' . $url . '" class="skiplinks">' . $title . '</a></li>';
        }
        $menu_list .= '</ul></nav>';
    } else {
        $menu_list = '<ul><li>Menu "' . $menu_name . '" not defined.</li></ul>';
    }
    if (get_option('acp_skiplinks', false)) {
        echo $menu_list;
    }
    die;
}
开发者ID:amarcinkowski,项目名称:accessible-poetry,代码行数:28,代码来源:acp_skiplinks.php


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