Add menu item during node_save in Drupal 6
Use this code for adding a menu item when saving a node. The menu item will automatically link to the node. Link_title is the display name of the menu item. Menu_name is the unique name of the menu you are adding to. The value can be found in the database under table menu_custom and column menu_name. Plid is the parent mlid that the menu item is assigned to. 0 for the root of the menu.
$node = new stdClass(); $node->type = 'page'; node_object_prepare($node); $node->title = 'My Node'; //add menu item $node->menu['link_title'] = 'Menu Item Name'; $node->menu['menu_name'] = 'custom-menu-name'; $node->menu['plid'] = 0; $node->menu['weight'] = 1; node_save($node);
Add new comment