本文整理汇总了PHP中is_nav_menu函数的典型用法代码示例。如果您正苦于以下问题:PHP is_nav_menu函数的具体用法?PHP is_nav_menu怎么用?PHP is_nav_menu使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_nav_menu函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: infinity_register_bp_menu
/**
* Register and create a custom BuddyPress menu
*/
function infinity_register_bp_menu($menu_name)
{
global $blog_id;
// check BP reqs and if our custom default menu already exists
if (function_exists('bp_core_get_directory_pages') && BP_ROOT_BLOG == $blog_id && !is_nav_menu($menu_name)) {
// doesn't exist, create it
$menu_id = wp_create_nav_menu($menu_name);
// get bp pages
$pages = bp_core_get_directory_pages();
// allowed pages
$pages_ok = array('activity' => true, 'blogs' => true, 'forums' => true, 'groups' => true, 'links' => true, 'members' => true);
// loop all pages
foreach ($pages as $config) {
// make sure we support this page
if (array_key_exists($config->name, $pages_ok)) {
// yep, add page as a nav item
wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'post_type', 'menu-item-status' => 'publish', 'menu-item-object' => 'page', 'menu-item-object-id' => $config->id, 'menu-item-title' => $config->title, 'menu-item-attr-title' => $config->title, 'menu-item-classes' => 'icon-' . $config->name));
}
}
// get location settings
$locations = get_theme_mod('nav_menu_locations');
// is main menu location set yet?
if (empty($locations['main-menu'])) {
// nope, set it
$locations['main-menu'] = $menu_id;
// update theme mode
set_theme_mod('nav_menu_locations', $locations);
}
}
}
示例2: bb_register_navmenus
/**
*
* Function for registering wp_nav_menu() in 3 locations
*/
function bb_register_navmenus()
{
register_nav_menus(array('Top' => __('Top Navigation'), 'Header' => __('Header Navigation'), 'Footer' => __('Footer Navigation')));
// Check if Top menu exists and make it if not
if (!is_nav_menu('Top')) {
$menu_id = wp_create_nav_menu('Top');
$menu = array('menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'), 'menu-item-title' => 'Home');
wp_update_nav_menu_item($menu_id, 1, $menu);
}
// Check if Header menu exists and make it if not
if (!is_nav_menu('Header')) {
$menu_id = wp_create_nav_menu('Header');
$menu = array('menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'), 'menu-item-title' => 'Home');
wp_update_nav_menu_item($menu_id, 1, $menu);
}
// Check if Footer menu exists and make it if not
if (!is_nav_menu('Footer')) {
$menu_id = wp_create_nav_menu('Footer');
$menu = array('menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'), 'menu-item-title' => 'Home');
wp_update_nav_menu_item($menu_id, 1, $menu);
}
// Get any menu locations that dont have a menu assigned to it and give it on
/*
$loc = array('Top', 'Header', 'Footer');
if ( has_nav_menu( $location )) {
$locations = get_nav_menu_locations();
return (!empty( $locations[ $location ] ));
}
*/
}
示例3: create_test_menus
/**
* create optional test nav menu
*
* At least two custom menus should be created in order to test a theme
* The standard Theme data file now ships with optimal menus built-in
* This method actually makes sense with custom WXR files only
*
* @since 0.2
*/
private function create_test_menus()
{
$pages = get_all_page_ids();
$items = array();
foreach ($pages as $page_ID) {
$info = get_page($page_ID);
$items[$info->post_title] = get_permalink($page_ID);
}
# pick three random entries
$random = array_rand($items, 3);
# build menus
$menus = array('Full Menu' => array('slug' => 'full-menu', 'menu_items' => $items), 'Short Menu' => array('slug' => 'short-menu', 'menu_items' => array($items[$random[0]], $items[$random[1]], $items[$random[2]])));
# register menus
foreach ($menus as $title => $data) {
register_nav_menu($data['slug'], $title);
if (false == is_nav_menu($title)) {
$menu_ID = wp_create_nav_menu($title);
foreach ($data['menu_items'] as $name => $url) {
$add_item = array('menu-item-type' => 'custom', 'menu-item-url' => $url, 'menu-item-title' => $name);
wp_update_nav_menu_item($menu_ID, 0, $add_item);
}
WP_CLI::success('Created menu ' . $title);
}
}
}
示例4: register_navmenus
function register_navmenus()
{
register_nav_menus(array('Header' => __('Header Navigation')));
// Check if Header menu exists and make it if not
if (!is_nav_menu('Header')) {
$menu_id = wp_create_nav_menu('Header');
}
}
示例5: create_pages
function create_pages()
{
// Argument dla strony Głównej
$main_page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'main', 'page_template' => 'page-templates/main.php', 'post_title' => 'Główna', 'post_content' => '');
if (get_page_by_title('Główna') == null) {
$main_page = wp_insert_post($main_page_args);
update_option('page_on_front', $main_page);
update_option('show_on_front', 'page');
echo '<div class="updated"> <p>Utworzono stronę "Główna"</p></div>';
}
// Argument dla strony Blog
$blog_page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'blog', 'page_template' => 'page-templates/blog.php', 'post_title' => 'Blog', 'post_content' => '');
if (get_page_by_title('Blog') == null) {
wp_insert_post($blog_page_args);
echo '<div class="updated"> <p>Utworzono stronę "Blog"</p></div>';
}
// Argument dla strony Projekty
$projects_page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'projects', 'page_template' => 'page-templates/projects.php', 'post_title' => 'Projekty', 'post_content' => '');
if (get_page_by_title('Projekty') == null) {
wp_insert_post($projects_page_args);
echo '<div class="updated"> <p>Utworzono stronę "Projekty"</p></div>';
}
// Argument dla strony Login
$login_page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'login', 'page_template' => 'page-templates/login.php', 'post_title' => 'Logowanie', 'post_content' => '');
if (get_page_by_title('Logowanie') == null) {
wp_insert_post($login_page_args);
echo '<div class="updated"> <p>Utworzono stronę "Logowanie"</p></div>';
}
// Argument dla strony Członkowie
$members_page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'members', 'page_template' => 'page-templates/members.php', 'post_title' => 'Członkowie', 'post_content' => '');
if (get_page_by_title('Członkowie') == null) {
wp_insert_post($members_page_args);
echo '<div class="updated"> <p>Utworzono stronę "Członkowie"</p></div>';
}
// Argument dla strony O nas
$about_page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'about', 'post_title' => 'O nas', 'post_content' => 'Jakiś tekst o nas');
if (get_page_by_title('O nas') == null) {
wp_insert_post($about_page_args);
echo '<div class="updated"> <p>Utworzono stronę "O nas"</p></div>';
}
// Tworzymy menu i dodajemy do niego pozycje //
if (!is_nav_menu('topbar_menu')) {
$menu_id = wp_create_nav_menu('topbar_menu');
wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => 'Blog', 'menu-item-object' => 'page', 'menu-item-object-id' => get_page_by_path('blog')->ID, 'menu-item-type' => 'post_type', 'menu-item-status' => 'publish'));
wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => 'Członkowie', 'menu-item-object' => 'page', 'menu-item-object-id' => get_page_by_path('members')->ID, 'menu-item-type' => 'post_type', 'menu-item-status' => 'publish'));
wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => 'O nas', 'menu-item-object' => 'page', 'menu-item-object-id' => get_page_by_path('about')->ID, 'menu-item-type' => 'post_type', 'menu-item-status' => 'publish'));
// Grab the theme locations and assign our newly-created menu
// to the BuddyPress menu location.
if (!has_nav_menu('topbar_menu')) {
$locations = get_theme_mod('nav_menu_locations');
$locations['main_menu'] = $menu_id;
set_theme_mod('nav_menu_locations', $locations);
echo '<div class="updated"> <p>Utworzono menu</p></div>';
}
}
}
示例6: cbox_theme_register_default_menu
/**
* Register and create a default menu in CBOX.
*
* @param array $args Arguments to register the default menu:
* 'menu_name' - The internal menu name we should give our new menu.
* 'location' - The nav menu location we want our new menu to reside.
* 'pages' - Associative array of pages. Sample looks like this:
* array(
* array(
* 'title' => 'Home',
* 'position' => 0,
* 'url' => home_url( '/' ) // custom url
* ),
* array(
* 'title' => 'Members',
* 'position' => 10,
* 'bp_directory' => 'members' // match bp component
* ),
* )
*/
function cbox_theme_register_default_menu($args = array())
{
global $blog_id;
if (empty($args['menu_name']) || empty($args['location']) || empty($args['pages'])) {
return false;
}
if (!is_array($args['pages'])) {
return false;
}
// check BP reqs and if our custom default menu already exists
if (function_exists('bp_core_get_directory_pages') && BP_ROOT_BLOG == $blog_id && !is_nav_menu($args['menu_name'])) {
// menu doesn't exist, so create it
$menu_id = wp_create_nav_menu($args['menu_name']);
// get bp pages
$bp_pages = bp_core_get_directory_pages();
// now, add the pages to our menu
foreach ($args['pages'] as $page) {
// default args
$params = array('menu-item-status' => 'publish', 'menu-item-title' => $page['title'], 'menu-item-classes' => 'icon-' . !empty($page['bp_directory']) ? $page['bp_directory'] : sanitize_title($page['title']), 'menu-item-position' => $page['position']);
// support custom menu type
if (!empty($page['type'])) {
$params['menu-item-type'] = $page['type'];
}
// support custom url
if (!empty($page['url'])) {
$params['menu-item-url'] = $page['url'];
}
// add additional args for bp directories
if (!empty($page['bp_directory'])) {
// bp directory page doesn't exist, so stop!
if (!array_key_exists($page['bp_directory'], get_object_vars($bp_pages))) {
continue;
}
// yep, add page as a nav item
$params['menu-item-type'] = 'post_type';
$params['menu-item-object'] = 'page';
$params['menu-item-object-id'] = $bp_pages->{$page['bp_directory']}->id;
}
wp_update_nav_menu_item($menu_id, 0, $params);
$params = array();
}
// get location settings
$locations = get_theme_mod('nav_menu_locations');
// is our menu location set yet?
if (empty($locations[$args['location']])) {
// nope, set it
$locations[$args['location']] = $menu_id;
// update theme mode
set_theme_mod('nav_menu_locations', $locations);
}
return true;
}
}
示例7: free01_setup
function free01_setup()
{
/***** Navigation & Menu *****/
$menus = array(__('Main menu', 'free01') => __('Main menu', 'free01'));
foreach ($menus as $key => $value) {
if (!is_nav_menu($key)) {
wp_update_nav_menu_item(wp_create_nav_menu($key), 1);
}
}
if (function_exists('register_nav_menus')) {
register_nav_menus($menus);
}
remove_action('wp_head', '_admin_bar_bump_cb');
}
示例8: menu_customizer_delete_menu_ajax
/**
* Ajax handler for deleting a menu.
*
* @since Menu Customizer 0.0.
*/
function menu_customizer_delete_menu_ajax()
{
check_ajax_referer('customize-menus', 'customize-nav-menu-nonce');
if (!current_user_can('edit_theme_options')) {
wp_die(-1);
}
$menu_id = absint($_POST['menu_id']);
if (is_nav_menu($menu_id)) {
$deletion = wp_delete_nav_menu($menu_id);
if (is_wp_error($deletion)) {
echo $deletion->message();
}
} else {
echo __('Error: invalid menu to delete.');
}
wp_die();
}
示例9: print_menu_if_exists
/**
* Print a menu only if that menu exists and has content.
*
* @param string $menu_name Name of the wp_nav_menu.
* @param string $menu_title Title to go with menu
*/
function print_menu_if_exists($menu_name, $menu_title = '')
{
/* Get reference to menu without printing the menu.
* This reference will point to $menu_name if it exists and to wp_page_menu
* if it doesn't.
*/
$menu = wp_nav_menu(array('echo' => false, 'menu' => $menu_name, 'fallback_cb' => '__return_false'));
/*
* Make sure menu both has content and is the right menu with name
* of [menu_name]. Otherwise, it could be pointing to wp_page_menu.
*
*/
if (!empty($menu) && is_nav_menu($menu_name)) {
$defaults = array('menu' => $menu_name, 'container' => false, 'menu_class' => 'resource-links');
echo '<div class="section--fp__resources">';
if (!empty($menu_title)) {
echo '<h5 class="resources__title">' . $menu_title . '</h5>';
}
wp_nav_menu($defaults);
echo '</div>';
}
}
示例10: import_menu
protected function import_menu($menu)
{
$_menu = $menu['menu'];
if (is_nav_menu($menu['menu']['slug'])) {
$local_menu = wp_get_nav_menu_object($menu['menu']['slug']);
$menu_id = $local_menu->term_id;
$update = true;
if (!empty($local_menu)) {
$local_menu = new cfd_menu($menu['menu']['slug']);
}
} else {
$menu_id = 0;
$update = false;
}
$insert_menu_id = wp_update_nav_menu_object($menu_id, array('menu-name' => $menu['menu']['name'], 'description' => $menu['menu']['description'], 'slug' => $menu['menu']['slug']));
if (is_wp_error($insert_menu_id)) {
$this->add_import_message('menus', '__error__', sprintf(__('Menu import failed for menu "%s". Error: ', 'cf-deploy'), $menu['menu']['name']) . $insert_menu_id->get_error_message());
return false;
}
// nuke existing menu items, trust me, its easier this way
if ($update) {
// Taken directly from wp_delete_nav_menu, wp-includes/nav-menu.php
$menu_objects = get_objects_in_term($insert_menu_id, 'nav_menu');
if (!empty($menu_objects)) {
foreach ($menu_objects as $item) {
wp_delete_post($item);
}
}
}
// handle menu items
if (!empty($menu['items'])) {
$this->menu_item_parent_map = array();
$processed_items = 0;
foreach ($menu['items'] as $item) {
if ($this->import_menu_item($item, $insert_menu_id)) {
$processed_items++;
}
}
}
// log rollback state
$item_change['menus'][$menu['menu']['slug']] = 'new';
if (!empty($local_menu)) {
$item_change['menus'][$menu['menu']['slug']] = $local_menu->get_data_for_transit();
}
$this->log_item_change($item_change);
return $processed_items == count($menu['items']);
}
示例11: yb_register_menus
function yb_register_menus()
{
global $ybwp_data;
$util_nav = $ybwp_data['opt-checkbox-utilnav'];
$wireframes = $ybwp_data['opt-checkbox-wireframes'];
add_theme_support('menus');
$menus = array('Main Navigation' => array('slug' => 'main-nav', 'menu_items' => array('Home' => array('url' => site_url(), 'slug' => 'home'))), 'Footer Navigation' => array('slug' => 'footer-nav', 'menu_items' => array('Home' => array('url' => site_url(), 'slug' => 'home'))));
/* optional utility navigation */
if (!empty($util_nav)) {
$menus['Utility Navigation'] = array('slug' => 'util-nav', 'menu_items' => array());
}
/* the menu for the wireframes pages. only shows in dev environments */
if ((WP_ENV == 'development' || WP_ENV == 'staging') && !empty($wireframes)) {
$menus['Wireframes Navigation'] = array('slug' => 'wireframes-nav', 'menu_items' => array('Home' => array('url' => site_url(), 'slug' => 'home')));
}
/* create menus */
foreach ($menus as $menu_title => $menu_var) {
/* register new nav menu */
register_nav_menu($menu_var['slug'], $menu_title);
if (!is_nav_menu($menu_title)) {
$menu_id = wp_create_nav_menu($menu_title);
/* populate menu items */
foreach ($menu_var['menu_items'] as $menu_item_name => $menu_item_args) {
$page_obj = get_page_by_path($menu_item_args['slug']);
$item = array('menu-item-object' => 'page', 'menu-item-type' => 'post_type', 'menu-item-object-id' => $page_obj->ID, 'menu-item-url' => $menu_item_args['url'], 'menu-item-title' => $menu_item_name, 'menu-item-status' => 'publish', 'menu-item-position' => $page_obj->menu_order);
wp_update_nav_menu_item($menu_id, 0, $item);
}
$locations = get_theme_mod('nav_menu_locations');
$locations[$menu_var['slug']] = $menu_id;
set_theme_mod('nav_menu_locations', $locations);
}
}
}
示例12: show_the_appropriate_menu
/**
* PHPDOC
*
* @param array $items An array of menu item post objects.
* @param object $menu The menu object.
* @param array $args An array of arguments used to retrieve menu item objects.
*
* @return array PHPDOC
*
* @since PHPDOC
*/
public function show_the_appropriate_menu($items, $menu, $args)
{
remove_action('wp_get_nav_menu_items', array(&$this, 'show_the_appropriate_menu'), 10, 3);
$alt_menu = $this->get_menu_alternative($menu->term_id);
if (is_nav_menu($alt_menu)) {
$items = wp_get_nav_menu_items($alt_menu, $args);
}
add_action('wp_get_nav_menu_items', array(&$this, 'show_the_appropriate_menu'), 10, 3);
return $items;
}
示例13: Build
private function Build($Options = null)
{
if ($Options !== null) {
$Options = wp_parse_args($Options, $this->Options);
} else {
$Options = $this->Options;
}
$Options = wp_parse_args($Options, $this->DefaultOptions);
$Options = apply_filters('gk_submenu_args', $Options);
extract($Options);
$depth = (int) $depth;
if (isset($child_of) && $child_of) {
$submenu = $child_of;
}
if (isset($start_from) && $start_from) {
$submenu = $start_from;
}
// if no menu specified, gets the lowest ID menu
if (!$menu || !is_nav_menu($menu)) {
$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->term_id;
break;
}
}
}
// still can't find a menu, we exit
if (!$menu || !is_nav_menu($menu)) {
return;
}
/* WPML support */
if (function_exists('icl_object_id')) {
global $sitepress;
/* not default language */
if (ICL_LANGUAGE_CODE !== $sitepress->get_default_language()) {
$translated_menu_id = icl_object_id($menu, 'nav_menu');
$menu = $translated_menu_id ? $translated_menu_id : $menu;
}
}
/* */
$menu_items = wp_get_nav_menu_items($menu);
if (is_tax() || is_category()) {
$_type = 'taxonomy';
} else {
$_type = 'post_type';
}
// current page is top level element
if ($submenu === 'current') {
global $wp_query;
$submenu = $this->get_associated_nav_menu_item($wp_query->get_queried_object_id(), $menu_items, $_type);
} else {
if ($submenu === 'top') {
global $post, $wp_query;
if ((is_a($post, 'stdClass') || is_a($post, 'WP_Post')) && (int) $post->ID) {
if ($submenu = $this->get_top_ancestor($wp_query->get_queried_object_id(), $menu_items, $_type)) {
$submenu = $submenu->ID;
}
}
}
}
// a submenu has been specified
if ($submenu !== 0) {
if (!$submenu) {
return;
}
$submenu_item = $submenu;
if (!is_object($submenu)) {
$submenu_item = $this->get_menu_item($submenu, $menu_items);
if (!$submenu_item) {
$submenu_item = $this->get_associated_nav_menu_item($submenu, $menu_items, $type);
}
if (!$submenu_item) {
return;
}
}
if (!$this->menu_item_has_child($submenu_item->ID, $menu_items)) {
return;
}
$submenu_id = $submenu_item->ID;
$this->top_level_item = $submenu_item;
global $GKSM_ID, $GKSM_MENUID;
$menu_object = wp_get_nav_menu_object($menu);
$GKSM_ID = $submenu_id;
$GKSM_MENUID = $menu_object->term_id;
}
if (!strpos($container_class, ' ')) {
$slug = '';
if (!empty($GLOBALS['wp_query']->get_queried_object()->post_name)) {
$slug = $GLOBALS['wp_query']->get_queried_object()->post_name;
} else {
if (!empty($GLOBALS['wp_query']->get_queried_object()->{$slug})) {
$slug = $GLOBALS['wp_query']->get_queried_object()->slug;
}
}
$container_class .= " {$container_class}-" . $slug;
}
// gets the nav menu
$args = array('container_class' => $container_class, 'menu' => $menu, 'show_description' => $show_description, 'depth' => $depth, 'is_gk_submenu' => $is_gk_submenu);
if (empty($args['walker'])) {
//.........这里部分代码省略.........
示例14: get_the_post_thumbnail
<?php
// The header image
// Check if this is a post or page, if it has a thumbnail, and if it's a big one
if (is_singular() && current_theme_supports('post-thumbnails') && has_post_thumbnail($post->ID) && ($image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'post-thumbnail')) && $image[1] >= HEADER_IMAGE_WIDTH) {
// Houston, we have a new header image!
echo get_the_post_thumbnail($post->ID, array(1102, 350), array('class' => 'headerimage'));
} elseif (get_header_image()) {
?>
<img src="<?php
header_image();
?>
" class="headerimage" width="<?php
echo HEADER_IMAGE_WIDTH;
?>
" height="<?php
echo HEADER_IMAGE_HEIGHT;
?>
" alt="" /><!-- end headerimage -->
<?php
}
?>
<div class="clear"></div>
<nav id="subnav">
<?php
if (is_nav_menu('Sub Menu')) {
wp_nav_menu(array('menu' => 'Sub Menu'));
}
?>
</nav><!-- end subnav -->
</header><!-- end header -->
示例15: register_menu
<?php
/*** Top navigation ***/
function register_menu()
{
register_nav_menu('Header', __('Header'));
}
add_action('init', 'register_menu');
if (!is_nav_menu('Header')) {
$menu_id = wp_create_nav_menu('Header');
wp_update_nav_menu_item($menu_id, 1);
}
class extended_walker extends Walker_Nav_Menu
{
function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output)
{
if (!$element) {
return;
}
$id_field = $this->db_fields['id'];
//display this element
if (is_array($args[0])) {
$args[0]['has_children'] = !empty($children_elements[$element->{$id_field}]);
}
//Adds the 'parent' class to the current item if it has children
if (!empty($children_elements[$element->{$id_field}])) {
array_push($element->classes, 'parent');
}
$cb_args = array_merge(array(&$output, $element, $depth), $args);
call_user_func_array(array(&$this, 'start_el'), $cb_args);
$id = $element->{$id_field};