So I am using this code to output nodes title:

<?php print render($title_prefix); ?>
<?php if ($title): ?><h2 class="title" id="page-title"><?php print $title; ?></h2><?php endif; ?>
<?php print render($title_suffix); ?>

What code do I need to output the content type's name (i.e. content type is Article, so output 'Article' inside each Article content type node page next to node title, above or below it)?


In D7 there is node_type_get_name



$node: A node object or string that indicates the node type to return

Return value

The node type name or FALSE if the node type is not found.

| improve this answer | |
  • This shoud be used in addition to the check isset($node) to avoid notices from PHP – mjs Aug 14 '15 at 12:22

You can access the $node object in page.tpl.php typically, as long as a $node object exists (i.e. you are on a node page). So you can use:

if (isset($node)) {
  // do something with $node

If you want to inspect $node (or anything else for that matter), you can use Devel module. When installed and enabled, it provides a function, dpm(), that will let you inspect arrays, objects, etc. as long as you are logged in as a user with permissions to view it. so dpm($node) will allow you to inspect the $node object.

The value closest to what you want is probably $node->type, but as MPD pointed out, that will give you a machine name, with spaces converted to underscores.

If you want to do it without writing any code, your best option is probably to use Views or Panels to pull that value and display it.

If you don't want to use those, here's how you would do it with a block:

  1. Create a block for the content type you want to display.
  2. Make the content "My Content Type Name" or whatever.
  3. Set the block to display in whatever region you want.
  4. Set the block to only display on content of "My Content Type Name".
  5. Save the block.
| improve this answer | |
  • Thanks for helping, but like I mentioned, I am a beginner and I have no experience on PHP at all. All I know is how to paste in code to template.php and etc. I am a designer - not a programmer, sadly. So I am pretty much not sure what to write in. – user13176 Jan 31 '13 at 23:09
  • 1
    php.net/print – beth Jan 31 '13 at 23:18
  • 1
    $node->type is just the machine name, not the pretty name – mpdonadio Feb 1 '13 at 0:38

If article is your content type machine name ,

if($node_details->type == 'article'){
   print 'Article or $node_details->type';

it will print your content type name in all of is node.Print this in you page.tpl before print $content so that you can print it before the node title.

| improve this answer | |
  • if you don't know the machine name of your content type, simply print the $node_details = node_load(arg(1)); and get the value of $node_details->type, this is the machine name of your content type . – Ranjani Feb 2 '13 at 6:47
  • $node->type will give you the machine name faster. If the thing being viewed is a node, you will have access to the $node object. – beth Feb 3 '13 at 1:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.