This question is really simple, i need to use the node id as an identifier and so i need to display it whenever a certain content type is shown. What's the best way to do this? i need to display the node with label and so on, i just don't want to make a custom field for something that's already a field.
You could add a hook_node_load() hook and copy the nid into a field like structure.
something like (untested)
function mymodule_node_load($nodes, $types) {
foreach ($nodes as $node) {
$node->nid_field['und']['value'] = $node->nid;
}
}
-
-
this was more like i thought because i wanted the nid to act like a field with a label and so on. – Nicola Peluchetti Jul 22 '11 at 7:50
-
-
It makes little sense to use the _load hook to add something that is already there. Load is for adding new data (or changing existing data). – berkes Aug 31 '11 at 10:39
Create a template for the content type and use <?php print $node->nid; ?>
Make a copy of node.tpl.php from modules/system and paste in your theme directory. Copy the code from inside node.tpl.php and create a new file called "node--YOURTYPE.tpl.php" (replace YOURTYPE with the name of the content type).
Inside that file you can place <?php print $node->nid; ?>
wherever you want the nid to be seen. You can add a label, wrap it in HTML to style it, whatever you like. Save the file and clear the cache to see the changes. Take a look at a node of that content type and you will see the node's nid.
-
@Nicola if you want a label, simply add it into the template with HTML... – Laxman13 Jul 22 '11 at 12:56
download display suite module.
add a custom code field
select token and the code is [node:nid]