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.

  1. $node = new stdClass();
  2. $node->type = 'page';
  3. node_object_prepare($node);
  4. $node->title = 'My Node';
  5. //add menu item
  6. $node->menu['link_title'] = 'Menu Item Name';
  7. $node->menu['menu_name'] = 'custom-menu-name';
  8. $node->menu['plid'] = 0;
  9. $node->menu['weight'] = 1;
  10. node_save($node);

Tags: 

Add new comment