Drupal: How to Get Know Type of Current Node
Problem:
It is necessary to get know type of the displayed node. There is no such info in Edit form.
Solution:
Alternatives
- Block with РНР code that shows node type
- Nodetype module
Block with PHP code that shows node type
Create a block with PHP input format and insert the following code to the block body:
<?php
if (arg(0)==’node’ && is_numeric(arg(1))) {
$node = node_load(arg(1));
echo ‘Тип текущей ноды: ‘. $node->type;
}
?>
Bock visibility: “Show block on specific pages: Show on every page except the listed pages." The block will be shown on nodes’ pages only – this is defined in the code.
It is better to show the lock for site admin only – just specify the desired role.
Nodetype module
You can install Nodetype module which allows to change node type.
ON the edit page for a node, you will find the drop-down list (select list). The current node type will be the default there. Select the node type and save settings.
This code is faster
In my tests:
– node_load(): 16ms
– db_query(): 0.4ms
arg(1)));
foreach($result as $record)
$type = $record->type;
echo ‘Node type is: ‘. $type;
}
?>
This code is faster
In my tests:
– node_load(): 16ms
– db_query(): 0.4ms
if (arg(0)==’node’ && is_numeric(arg(1))) {
$result = db_query(‘SELECT n.type FROM {node} n WHERE n.nid = :nid’, array(‘:nid’ => arg(1)));
foreach($result as $record)
$type = $record->type;
echo ‘Node type is: ‘. $type;
}