display content type name?

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by convoke on May 18, 2011 at 5:44pm

I've created a child theme of Zen for a website I'm working on.

What I'm trying to do right now is display the content type name (not machine name!!!) below the title. The $type variable only returns the machine name... is there a way to return the "display" name of a content type?

For example, the machine name for one of my content types is "article", but the display name is "Stuff". How can I go about returning "Stuff" instead of "article"?

Comments

If you're using Drupal 6, you

Posted by Garrett Albright on May 20, 2011 at 9:30am

If you're using Drupal 6, you can use node_get_types():

<?php
$human_name
= node_get_types('name', $type);
?>

Drupal 7 is a smidge trickier - use node_type_get_types(), which will return an array full of data on all of a site's types. Then pluck the "name" attribute from the relevant type.

<?php
$types
= node_type_get_types();
$human_name = $types[$type]->name;
?>

not work

Posted by mayur.pimple on February 8, 2012 at 5:04am

Hi this code not working in my website.
$human_name = node_get_types('name', $type);

In Drupal 7

Posted by jdjeet on July 12, 2012 at 1:13pm

Hi,

In drupal 7, use node_type_get_name to extract Real Content type name from machine name.

Example please...

Posted by monalisab on April 9, 2013 at 8:09am

Hi Jeet,

Could you please provide an example for node_type_get_name use.
I am getting an multidimensional array by using node_type_get_types() .

But unable to get only content type names for my custom admin configuration form page. :(

Its solved now... I just

Posted by monalisab on April 9, 2013 at 9:36am

Its solved now...

I just wanted it as a check-box list for custom form.

// Load all node types.
$types = node_type_get_types();

$checkboxes = array();

foreach ($types as $val) {
$checkboxes[$val->type] = $val->name;
}

As jdjeet says use

Posted by vaudaville on August 12, 2012 at 11:54am

As jdjeet says use node_type_get_name
For Drupal 7 the following will display the human readable name of the content type in a node when added to node.tpl.php:

<?php
print node_type_get_name($type);
?>

AltStyle によって変換されたページ (->オリジナル) /