This would be VERY helpful for site development, and potentially beneficial as a persistent feature on a production site.

I'm pretty sure I did this on an old D7 site of mine, but that was, like, years ago. And since everything is changing fast, I am now seeking advice on what would be the "best practice" method(s) for

  • Displaying the content type (probably at the top of the node display) with the output of a node.

Some ideas (which I assume could work, but don't know how):

  1. Edit the tpl file for various node types
  2. Create a custom field for various content types (and display it)

No. 1 would be fast and would apply to many content types at once (and is also easily disabled when no longer wanted). No. 2 would take more time, but would have the benefit of being able to manipulate and display the field differently for different display formats, and with Views. What I am missing is the php function call that will produce a string equivalent to the content type. Any assistance is greatly appreciated.

Thanks,
—Eric

Most helpful answers

As for outputting the content type in a node's template file, here's how to do that:

<p class="content-type"><?php print $node->type; ?></p> 

Add that to node.tpl.php.

You say this would be helpful for site development, so I assume that means this doesn't need to be visible to anonymous users. If that's the case, while not displayed on the node itself, if you simply click Edit you'll see the content type displayed in the page title:

Comments

You say this would be helpful for site development, so I assume that means this doesn't need to be visible to anonymous users. If that's the case, while not displayed on the node itself, if you simply click Edit you'll see the content type displayed in the page title:

As for outputting the content type in a node's template file, here's how to do that:

<p class="content-type"><?php print $node->type; ?></p> 

Add that to node.tpl.php.

^^Two very helpful and quick answers! Thanks, BWPanda!

Olafski's picture

One more idea: a Views block with node related information.

  • Create a View with field Content: Type.
  • Add a contextual filter Content: Nid (node ID), and provide the default value "Content ID from the URL".
  • Go to the Layout which displays your content type(s), and add the Views block created above.

Excellent, @Olafski!

Thanks for this tip. Very elegant solution.