0

I have an array like this :

Array(
  [0] => Array(
    [link_title] => Level == bod
    [link_path] => link1
    [menu_name] => parrent-child-menu
    [weight] => 1
    [expanded] => 1
  )
)
Array(
  [0] => Array(
    [link_title] => Level == About// us///
    [link_path] => link1
    [menu_name] => parrent-child-menu
    [weight] => 3
    [expanded] => 1
  )
)
Array(
  [0] => Array(
    [link_title] => Level == name12
    [link_path] => link1
    [menu_name] => parrent-child-menu
    [weight] => 5
    [expanded] => 1
  )
)
Array(
  [0] => Array(
    [link_title] => Level == name13
    [link_path] => link1
    [menu_name] => parrent-child-menu
    [weight] => 5
    [expanded] => 1
  )
)
Array(
  [0] => Array(
    [link_title] => Level == name14
    [link_path] => link1
    [menu_name] => parrent-child-menu
    [weight] => 5
    [expanded] => 1
  )
)

I want it in the following format:

Array ( [0] => Array ( [link_title] => Level == bod [link_path] => link1 [menu_name] => parrent-child-menu [weight] => 1 [expanded] => 1 [children] => Array ( [0] => Array ( [link_title] => Level == About// us/// [link_path] => link1 [menu_name] => parrent-child-menu [weight] => 3 [expanded] => 1 [children] => Array ( [0] => Array ( [link_title] => Level == name12 [link_path] => link1 [menu_name] => parrent-child-menu [weight] => 5 [expanded] => 1 )

) Array ( [0] => Array ( [link_title] => Level == name13 [link_path] => link1 [menu_name] => parrent-child-menu [weight] => 5 [expanded] => 1 ) ) Array ( [0] => Array ( [link_title] => Level == name14 [link_path] => link1 [menu_name] => parrent-child-menu [weight] => 5 [expanded] => 1 ) ) ) ) )

)

0

You need to set the value of plid to the mlid of the parent link. For example, you need to have this kind of menu structure.

About
  Vision
  Mission
  History

To create that programmatically you need first to create the About then get the mlid. After that you are good to create the Vision, Mission, and History as you have the About mlid already. Please see menu_link_save. Check this related thread as well.

0

See below example, hope you will get the solution to create parent-child menu programmatically.


$items['hotels'] = array(
'title' => 'Hotel Process',
'page callback' => 'hotels_page',
'access arguments' => array('access content'),
'weight' => 1,
);
$items['hotels/hotels2'] = array(
'title' => 'Hotel Statistics',
'page callback' => 'hotels_page',
'access arguments' => array('access content'),
'weight' => 1,
);

This also works:


$items['hotels'] = array(
'children' => array('hotels2'),
'title' => 'Hotel Process',
'page callback' => 'hotels_page',
'access arguments' => array('access content'),
'weight' => 1,
);
$items['hotels/hotels2'] = array(
'parent' => array('hotels'),
'title' => 'Hotel Statistics',
'page callback' => 'hotels_page',
'access arguments' => array('access content'),
'weight' => 1,
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.