(copied from handbook http://drupal.org/node/11816 - I thought it might be better to discuss this in the forums rather than risk a lengthy thread on a handbook page which currently benefits from clarity!)
content type name
JohnG - March 6, 2006 - 04:25
Despite this question going unanswered many times in the forums, I found the answer (I think) in Moshe's organic groups module.
Place this at the top of your node.tpl.php:
<?php
$type = (node_invoke($node->type, 'node_name'));
?>and then call
<?php print $type ?>where you want it inline.
this gives you the content type label rather than the module name, so it's much better than the traditional hack: <?php print $node->type ?>
It works for me!
=======================
Update For Drupal 4.7
alexis - March 13, 2006 - 20:23
Just wanted to add that the proper code for 4.7 would be:
<?php
$type = (node_invoke($node->type, 'node_info'));
?>and then
<?php print $type[$node->type]['name']; ?>Alexis Bellido - Ventanazul web solutions
==========================
Works for me, too. Don't
zwhalen - March 13, 2006 - 20:11
Works for me, too. Don't know what it means in terms of processing time or db usage or whatever, but it seems to work well. Thanks!
Comments
overheads
I had wondered about Zwalen's question about the 'overheads' of this method too. I guess a function in the node.tpl.php is going to get called when almost every page loads, so the function does need to be pretty slick ...
From what I can see from the API references http://drupaldocs.org/api/4.6/function/node_invoke seems to find the data in some part of the $node array (?) ... at least (AFAIK) it doesn't do any $sql database queries.
I would any appreciate advice on this one too.
thank you
Very sleek.
Caroline
Who am I | Where are we
11 heavens
Caroline
11 heavens.com
OR...
<?phpprint node_get_name($node->type);
?>
Definition of node_get_name() : Determine the human readable name for a given type.
Parameters : Either a node object, a node array, or a string containing the node type.
Return value : The human readable name of the node type.
Source : http://api.drupal.org/api/4.7/function/node_get_name
Code :
<?phpfunction node_get_name($node) {
return _node_names('name', $node);
}
?>
Does that function make a db_query ? From the look it, I don't think so :
http://api.drupal.org/api/4.7/function/_node_names
More stuff in our toolkit!
Thanks John, I just saw this and I though it may interest you. ONE year later! LOL...
That's for 4.7.x.
Caroline
Who am I | Where are we
11 heavens
Caroline
11 heavens.com
ah - the fruits of progress
ah - the fruits of progress
:)
For Drupal 5
To get the human readable name of a content type in Drupal 5 just add in your node.tpl.php
<?phpprint node_get_types('name', $node)
?>
Even better
I find. Thanks.
Caroline
Who am I | Where are we
11 heavens
Caroline
11 heavens.com
Wow! That easy hey!
Thanks! This is a must when you have many content types showing on the front page as it becomes confusing to guess what is what then...
LDdB
Easy
Thanks!
In Drupal 5 and 6
Relying on this function instead: http://api.drupal.org/api/function/node_get_types ...
<?phpprint node_get_types('name', $node);
?>
If you don't want 'page' to appear for pages, use this:
<?phpprint $node->type != 'page' ? node_get_types('name', $node) : '';
?>
If you wish to exclude more than 1 content types from being printed (their name, that is!), use something like this:
<?phpif (!in_array($node->type, array('story', 'page'))) { print node_get_types('name', $node); }
?>
Caroline
11 heavens.com
Caroline
11 heavens.com
How to work with i18n "Content Types" module?
node_get_types( ) is nice, but is there another way to display node-types in different languages works with the i18n "Content Types" module?
Much thanks. :)
意思意思而已。
It might be cleaner to put
It might be cleaner to put this in a preprocess_node function in template.php as
vars['type'] = node_get_types('name', $node);and then print out $type in a tpl.php file.
Evolving Web: Drupal Consulting + Development in Montreal