欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

如何在Drupal当中获取node id?

shiping1 的头像

如何在Drupal当中获取node id?

猪跑啦独家原创专稿,欢迎您转载本文,转载请注明来源。
标签: node nid node_load

第一种方法:

1
2
3
4
5
//get node id
 global $node;
 print_r($node);
 $nid = $node->nid;
 dsm(strval($nid));

 

第二种方法:使用url ''node/{nid}'  :

1
2
3
4
5
6
if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
  $node = node_load(arg(1));
  print_r($node);
  // Do something with $node
  // If all you need is the nid you can use
  // $nid = arg(1)

 

 

第三种方法:

1
2
3
$node = menu_get_object();
$nid=$node->nid;
dsm(strval($nid));

参考资料:

http://drupal.stackexchange.com/questions/6638/get-a-node-id-from-the-url

来自 http://www.drupalla.com/node/2267
普通分类: