[英]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?如何找到路径指向的节点的 nid?
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:您可以使用 menu_get_object:
$node = menu_get_object();
See http://api.drupal.org/api/drupal/includes--menu.inc/function/menu_get_object/6见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...在 Drupal 6...
If you know the url alias, you can retrieve the internal system path:如果您知道 url 别名,则可以检索内部系统路径:
$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:从 php 中,查看/编辑节点时,您还可以像这样检索它:
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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.