Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By bstrange on
How do you determine a node's ID? I am using several programs that need the node ID to insert content (such as panels) and the only way to add content to the selected panel is to input the NID...
I can't find the NID anywhere, ried searching here, google etc under "how do i determine node id nid in drupal 6" but found nothing.
Seems like this should be something easily viewable when I click on content management but apparently not...
any help would be greatly appreciated.
TIA :)
Comments
Some programs allow for title
Some programs allow for title (they use auto complete) as well as node (though not all).
By default nodes have a path of node/{nid} so if you visit the administer content list, look for the title and hover over it you can find the nid. If you are using alias, hover over the edit link (will be of the form node/{nid}/edit).
You could also check out the
You could also check out the About This Node module.
PHP code
Here's some PHP code that should give you the Node ID of the node you're currently viewing...
Without context, $nid is not
Without context, $nid is not a meaningful variable. Where/how do you expect it to be set?
Whoops
I think I must have read his question too quickly and assumed he wanted to know how to get the ID for the node he was currently viewing, such as when he's inserting something into a node type's template that needs the Node ID of that node.
After re-reading his question, I realize my answer was pretty incomplete and out-of-context.
Inserting content
The way I read your post, it looks like you are trying to create node content automatically outside the Drupal framework, and are trying to make sure the node IDs are generated correctly. If this is correct, the node ID is automatically generated by the database (it's an auto-increment field), so this is something you don't have to worry about. If you are trying to modify existing content automatically, please provide us with step by step details of how you are determining which content needs to be changed, and how the program making the changes fits into the Drupal framework in your scenario.
Actually, when using panels
Actually, when using panels to make custom pages, it does not use node titles when inputing content into a given section of the panels; it only uses node ID. Being able to determine the node ID will allow me to put specific nodes in specific sections of the panel page.
BTW, thanks to everyone for
BTW, thanks to everyone for their replies. Nevets solution (mousing over edit) seemed the simple route and worked perfectly for identifing the node.
Thanks again :)
You can use this snippet
You can use this snippet
function currentnode_nid(){
if (arg(0)=='node' && is_numeric(arg(1)))
return arg(1);
else
return 0;
}
function currentnode(){
return node_load(currentnode_nid());
}
it will return the current node id.
You can simplify that code
You can simplify that code to
Thank you so much! I looked
Thank you so much! I looked for this all over the web. :) Everyone seem just to grab the node number from the URL, which is such an awkward way of passing data within a web application that I'd hesitate to admit using such a method. :)