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


PHP wp_update_nav_menu_item函数代码示例

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


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

示例1: automatic_add_sub_pages

 /**
  * When publishing a new child page, add it to the appropriate custom menu.
  * @param string $post_id current edit post id
  * @author Romain DORR
  */
 public static function automatic_add_sub_pages($post_id)
 {
     // Theme supports custom menus?
     if (!current_theme_supports('menus')) {
         return false;
     }
     // Published page has parent?
     $post = get_post($post_id);
     if (!$post->post_parent) {
         return;
     }
     // Get all menus for this theme
     $menus = get_registered_nav_menus();
     // Get all locations
     $locations = get_nav_menu_locations();
     // Get Plugin option
     $auto_add_option = get_option('menu_aasp_options');
     // if no menus are configured
     if (empty($auto_add_option)) {
         return false;
     }
     // Loop through the menus to find page parent
     foreach ($menus as $menu_name => $menu) {
         if (!isset($locations[$menu_name])) {
             continue;
         }
         $menu = wp_get_nav_menu_object($locations[$menu_name]);
         // Test if menu is configure for auto add submenus
         if (empty($auto_add_option[$menu->term_id])) {
             continue;
         }
         $menu_parent = null;
         $menu_items = wp_get_nav_menu_items($menu->term_id, array('post_status' => 'publish,draft'));
         if (!is_array($menu_items)) {
             continue;
         }
         foreach ($menu_items as $menu_item) {
             // Item already in menu?
             if ($menu_item->object_id == $post->ID) {
                 continue 2;
             }
             if ($menu_item->object_id == $post->post_parent) {
                 $menu_parent = $menu_item;
             }
         }
         // Add new item
         if ($menu_parent) {
             wp_update_nav_menu_item($menu->term_id, 0, array('menu-item-object-id' => $post->ID, 'menu-item-object' => $post->post_type, 'menu-item-parent-id' => $menu_parent->ID, 'menu-item-type' => 'post_type', 'menu-item-status' => 'publish'));
         }
     }
 }
开发者ID:romain-d,项目名称:menu-auto-add-subpages,代码行数:56,代码来源:admin.php

示例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 ] ));
    }
    */
}
开发者ID:jaredwilli,项目名称:3.0basics,代码行数:34,代码来源:functions.php

示例3: xt_install_menu

function xt_install_menu($global)
{
    $menu_id = wp_create_nav_menu('新淘客菜单');
    if ($menu_id) {
        //home
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'), 'menu-item-title' => '首页', 'menu-item-status' => 'publish', 'menu-item-position' => 1));
        //shares
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_shares_search_url(), 'menu-item-title' => '逛街啦', 'menu-item-status' => 'publish', 'menu-item-position' => 2));
        //albums
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_albums_search_url(), 'menu-item-title' => '专辑', 'menu-item-status' => 'publish', 'menu-item-position' => 3));
        //taobaos
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_taobao_search_url(), 'menu-item-title' => '淘宝', 'menu-item-status' => 'publish', 'menu-item-position' => 6));
        //paipais
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_paipai_search_url(), 'menu-item-title' => '拍拍', 'menu-item-status' => 'publish', 'menu-item-position' => 7));
        //bijias
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_bijia_search_url(), 'menu-item-title' => '比价', 'menu-item-status' => 'publish', 'menu-item-position' => 8));
        //tuans
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_tuan_search_url(), 'menu-item-title' => '团购', 'menu-item-status' => 'publish', 'menu-item-position' => 9));
        //coupons
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_coupon_search_url(), 'menu-item-title' => '折扣', 'menu-item-status' => 'publish', 'menu-item-position' => 10));
        //temais
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_temai_search_url(), 'menu-item-title' => '特卖', 'menu-item-status' => 'publish', 'menu-item-position' => 11));
        //stars
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_site_url('stars'), 'menu-item-title' => '明星', 'menu-item-status' => 'publish', 'menu-item-position' => 12));
        //brands
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_site_url('brands'), 'menu-item-title' => '品牌', 'menu-item-status' => 'publish', 'menu-item-position' => 13));
        set_theme_mod('nav_menu_locations', array('primary' => $menu_id));
        $global['isMenu'] = 1;
        update_option(XT_OPTION_GLOBAL, $global);
    }
}
开发者ID:aspirin,项目名称:wp-xintaoke,代码行数:31,代码来源:xt-installer-functions.php

示例4: landing_setup

 function landing_setup()
 {
     load_theme_textdomain('landing', get_template_directory() . '/languages');
     add_theme_support("title-tag");
     add_theme_support('menus');
     add_theme_support('post-thumbnails');
     $menu_name = 'landing';
     $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' => __('Обо мне', 'landing'), 'menu-item-url' => home_url('/#about'), 'menu-item-status' => 'publish'));
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Резюме', 'landing'), 'menu-item-url' => home_url('/#resume'), 'menu-item-status' => 'publish'));
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Портволио', 'landing'), 'menu-item-url' => home_url('/#portfolio'), 'menu-item-status' => 'publish'));
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Контакты', 'landing'), 'menu-item-url' => home_url('/#contacts'), 'menu-item-status' => 'publish'));
     }
     $menu_name = 'social';
     $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' => __('Twitter profile', 'landing'), 'menu-item-target' => '_blank', 'menu-item-url' => '#', 'menu-item-classes' => 'fa fa-twitter', 'menu-item-status' => 'publish'));
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Facebook profile', 'landing'), 'menu-item-target' => '_blank', 'menu-item-url' => '#', 'menu-item-classes' => 'fa fa-facebook', 'menu-item-status' => 'publish'));
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Github profile', 'landing'), 'menu-item-target' => '_blank', 'menu-item-url' => '#', 'menu-item-classes' => 'fa fa-github', 'menu-item-status' => 'publish'));
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Vk profile', 'landing'), 'menu-item-target' => '_blank', 'menu-item-url' => '#', 'menu-item-classes' => 'fa fa-vk', 'menu-item-status' => 'publish'));
     }
 }
开发者ID:CrystalEller,项目名称:LandingPage,代码行数:25,代码来源:functions.php

示例5: duplicate

 function duplicate($id = null, $name = null)
 {
     // sanity check
     if (empty($id) || empty($name)) {
         return false;
     }
     $id = intval($id);
     $name = sanitize_text_field($name);
     $source = wp_get_nav_menu_object($id);
     $source_items = wp_get_nav_menu_items($id);
     $new_id = wp_create_nav_menu($name);
     if (!$new_id) {
         return false;
     }
     // key is the original db ID, val is the new
     $rel = array();
     $i = 1;
     foreach ($source_items as $menu_item) {
         $args = array('menu-item-db-id' => $menu_item->db_id, 'menu-item-object-id' => $menu_item->object_id, 'menu-item-object' => $menu_item->object, 'menu-item-position' => $i, 'menu-item-type' => $menu_item->type, 'menu-item-title' => $menu_item->title, 'menu-item-url' => $menu_item->url, 'menu-item-description' => $menu_item->description, 'menu-item-attr-title' => $menu_item->attr_title, 'menu-item-target' => $menu_item->target, 'menu-item-classes' => implode(' ', $menu_item->classes), 'menu-item-xfn' => $menu_item->xfn, 'menu-item-status' => $menu_item->post_status);
         $parent_id = wp_update_nav_menu_item($new_id, 0, $args);
         $rel[$menu_item->db_id] = $parent_id;
         // did it have a parent? if so, we need to update with the NEW ID
         if ($menu_item->menu_item_parent) {
             $args['menu-item-parent-id'] = $rel[$menu_item->menu_item_parent];
             $parent_id = wp_update_nav_menu_item($new_id, $parent_id, $args);
         }
         // allow developers to run any custom functionality they'd like
         do_action('duplicate_menu_item', $menu_item, $args);
         $i++;
     }
     return $new_id;
 }
开发者ID:robertmeans,项目名称:evergreentaphouse,代码行数:32,代码来源:duplicate-menu.php

示例6: processMenu

 private function processMenu(&$menu)
 {
     $objMenu = wp_get_nav_menu_object($menu->slug);
     if (!$objMenu) {
         $id = wp_create_nav_menu($menu->slug);
         $objMenu = wp_get_nav_menu_object($menu->slug);
     }
     $menuId = $objMenu->term_id;
     $menu->id = $menuId;
     wp_set_current_user(1);
     $loggedInmenuItems = wp_get_nav_menu_items($menu->slug);
     wp_set_current_user(0);
     $notloggedInmenuItems = wp_get_nav_menu_items($menu->slug);
     $existingMenuItems = array_merge($loggedInmenuItems, $notloggedInmenuItems);
     foreach ($existingMenuItems as $existingMenuItem) {
         $ret = wp_delete_post($existingMenuItem->ID, true);
     }
     foreach ($menu->items as &$objMenuItem) {
         $newTarget = findTargetPostId($objMenuItem->meta->postMeta['_menu_item_object_id'][0]);
         $parentItem = $this->findMenuItem($objMenuItem->meta->postMeta['_menu_item_menu_item_parent'][0]);
         $args = ['menu-item-title' => $objMenuItem->meta->post_title, 'menu-item-position' => $objMenuItem->meta->menu_order, 'menu-item-description' => $objMenuItem->meta->post_content, 'menu-item-attr-title' => $objMenuItem->meta->post_title, 'menu-item-status' => $objMenuItem->meta->post_status, 'menu-item-type' => $objMenuItem->meta->postMeta['_menu_item_type'][0], 'menu-item-object' => $objMenuItem->meta->postMeta['_menu_item_object'][0], 'menu-item-object-id' => $newTarget, 'menu-item-url' => $objMenuItem->meta->postMeta['_menu_item_url'][0], 'menu-item-parent-id' => $parentItem];
         $ret = wp_update_nav_menu_item($menuId, 0, $args);
         $objMenuItem->id = $ret;
         foreach ($objMenuItem->meta->postMeta as $key => $meta) {
             if (in_array($key, $this->skipped_meta_fields) || substr($key, 0, 1) == '_') {
                 continue;
             }
             $val = $meta[0];
             update_post_meta($ret, $key, $val);
         }
     }
 }
开发者ID:eriktorsner,项目名称:bookwordpressdevops,代码行数:32,代码来源:Pushmenus.php

示例7: yb_page_menus_save_post

function yb_page_menus_save_post($post_id, $post_object)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (!isset($_POST['meta_box_nonce']) || !wp_verify_nonce($_POST['meta_box_nonce'], 'yb_page_menus_nonce')) {
        return;
    }
    /* If this is just a revision, don't save in menu */
    if (wp_is_post_revision($post_id)) {
        return;
    }
    /* save the data with update_post_meta */
    $all_menus = wp_get_nav_menus();
    /* save the data with update_post_meta */
    foreach ($all_menus as $menu) {
        $menuID = (int) $menu->term_id;
        if (isset($_POST['nav-menu-group']) && in_array($menu->name, $_POST['nav-menu-group'])) {
            if (!checkMenuForPage($menuID, $post_id)) {
                $itemData = array('menu-item-object-id' => $post_id, 'menu-item-title' => __(get_the_title($post_id)), 'menu-item-url' => get_permalink($post_id), 'menu-item-object' => 'page', 'menu-item-position' => $post_object->menu_order, 'menu-item-type' => 'post_type', 'menu-item-status' => 'publish');
                remove_action('save_post', 'yb_page_menus_save_post', 13, 2);
                wp_update_nav_menu_item($menuID, 0, $itemData);
                add_action('save_post', 'yb_page_menus_save_post', 13, 2);
            }
        } else {
            $isInMenu = checkMenuForPage($menuID, $post_id);
            if ($isInMenu) {
                wp_delete_post($isInMenu);
            }
        }
    }
}
开发者ID:shelbyneilsmith,项目名称:yb-theme,代码行数:32,代码来源:functions-page_menus.php

示例8: _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>&nbsp; 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>&nbsp; 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);
     }
 }
开发者ID:pivotlearning,项目名称:wpsite,代码行数:31,代码来源:king.update.php

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

示例10: 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);
         }
     }
 }
开发者ID:pixline,项目名称:wp-cli-theme-test-command,代码行数:34,代码来源:wp-cli-theme-test-command.php

示例11: 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);
        }
    }
}
开发者ID:shads196770,项目名称:cbox-theme,代码行数:33,代码来源:menus.php

示例12: beans_do_register_default_menu

/**
 * Register default menu.
 *
 * @since 1.0.0
 */
function beans_do_register_default_menu()
{
    // Stop here if a menu already exists.
    if (wp_get_nav_menus()) {
        return;
    }
    // Set up default menu.
    wp_update_nav_menu_item(wp_create_nav_menu(__('Navigation', 'beans')), 0, array('menu-item-title' => __('Home', 'beans'), 'menu-item-classes' => 'home', 'menu-item-url' => home_url('/'), 'menu-item-status' => 'publish'));
}
开发者ID:ThemeButler,项目名称:tm-demo,代码行数:14,代码来源:menu.php

示例13: 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>';
        }
    }
}
开发者ID:synergia,项目名称:mknm-synergia-theme,代码行数:56,代码来源:setup.php

示例14: test_wp_get_nav_menu_items_with_taxonomy_term

 public function test_wp_get_nav_menu_items_with_taxonomy_term()
 {
     register_taxonomy('wptests_tax', 'post', array('hierarchical' => true));
     $t = $this->factory->term->create(array('taxonomy' => 'wptests_tax'));
     $child_terms = $this->factory->term->create_many(2, array('taxonomy' => 'wptests_tax', 'parent' => $t));
     $term_menu_item = wp_update_nav_menu_item($this->menu_id, 0, array('menu-item-type' => 'taxonomy', 'menu-item-object' => 'wptests_tax', 'menu-item-object-id' => $t, 'menu-item-status' => 'publish'));
     $term = get_term($t, 'wptests_tax');
     $menu_items = wp_get_nav_menu_items($this->menu_id);
     $this->assertSame($term->name, $menu_items[0]->title);
     $this->assertEquals($t, $menu_items[0]->object_id);
 }
开发者ID:Benrajalu,项目名称:philRaj,代码行数:11,代码来源:nav-menu.php

示例15: setMenuItem

 private function setMenuItem($menu_item)
 {
     $args = array('menu-item-db-id' => $menu_item->db_id, 'menu-item-object-id' => $menu_item->object_id, 'menu-item-object' => $menu_item->object, 'menu-item-position' => $this->counter, 'menu-item-type' => $menu_item->type, 'menu-item-title' => $menu_item->title, 'menu-item-url' => $menu_item->url, 'menu-item-description' => $menu_item->description, 'menu-item-attr-title' => $menu_item->attr_title, 'menu-item-target' => $menu_item->target, 'menu-item-classes' => implode(' ', $menu_item->classes), 'menu-item-xfn' => $menu_item->xfn, 'menu-item-status' => $menu_item->post_status);
     $parent_id = wp_update_nav_menu_item($this->createdMenu, 0, $args);
     $rel[$menu_item->db_id] = $parent_id;
     if ($menu_item->menu_item_parent) {
         $args['menu-item-parent-id'] = $rel[$menu_item->menu_item_parent];
         $parent_id = wp_update_nav_menu_item($this->createdMenu, $parent_id, $args);
     }
     return !!$parent_id;
 }
开发者ID:Konstantinos-infogeek,项目名称:save-menu-as,代码行数:11,代码来源:MenuCloner.php


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