You are here

2 October 2014

This snippet shows you how to get menu link id (mlid) from node id (nid) using a simple query generated by abstraction layer in Drupal 7.

Source code viewer
  1. $mlid = reset(db_select('menu_links' , 'ml')
  2. ->condition('ml.link_path' , 'node/' . $nid)
  3. ->fields('ml' , array('mlid'))
  4. ->execute()
  5. ->fetchCol());
  6.  
  7. if (!empty($mild)) {
  8. // Use your menu link id (mlid) wisely...
  9. }
Programming Language: PHP