简体   繁体   中英

Find nid from node's internal path in Drupal?

I have a path like this:

/news/2011/05/26/some-story-path

How do I find the nid for the node that the path points to?

Edit

The path above is simply a string value that I have on another page. I need to obtain information about the node that the path links to.

You could use menu_get_object:

$node = menu_get_object();

See http://api.drupal.org/api/drupal/includes--menu.inc/function/menu_get_object/6

edit

I think you can specify your path like this

menu_get_object($type = 'node', $position = 1, $path = '/news/2011/05/26/some-story-path');

In Drupal 6...

If you know the url alias, you can retrieve the internal system path:

$nid = str_replace("node/","",drupal_lookup_path("source","my/drupal/path"));

From php, when viewing/editing a node, you can also retrieve it like so:

function get_current_nid () {
  if (arg(0) == 'node' && is_numeric(arg(1)) { return arg(1); }
  return null;
}

$nid = get_current_nid();
drupal_set_message("The current node id is: $nid");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM