
You want to print the content type name along with the 'submitted' info. This will be particularly useful for those who have created custom content types, with or without CCK.
Edit node.tpl.php to add the content type name within a span with a class name (e.g. 'content-type-name') and...
style that span element in your theme's style.css file.
In the following example, the human-readable name for the content type is 'News', and the content type is displayed to the right of the 'submitted' info. Let's try and achieve that.

Your file node.tpl.php may look like this before the edit (I am only providing a snippet of the template here):
<?php if ($submitted): ?>
<span class="submitted"><?php print $submitted; ?></span>
<?php endif; ?>If it does, then you will change the above snippet to that:
<?php if ($submitted): ?>
<span class="submitted"><?php print $submitted; ?> — <span class="content-type-name"><?php print node_get_types('name', $node); ?></span></span>
<?php endif; ?>You may want to exclude a certain content type. For example, you may not want 'page' to appear in page nodes. Whenever you want to exclude one content type, you will do like so:
<?php if ($submitted): ?>
<span class="submitted"><?php print $submitted; ?><?php print ($node->type != 'page') ? ' — <span class="content-type-name">' . node_get_types('name', $node) . '</span>' : ''; ?></span>
<?php endif; ?>When you want to exclude more than one content type, say 'story' and 'page', you will do like so:
<?php if ($submitted): ?>
<span class="submitted"><?php print $submitted; ?><?php print (!in_array($node->type, array('story', 'page'))) ? ' — <span class="content-type-name">' . node_get_types('name', $node) . '</span>' : ''; ?></span>
<?php endif; ?>This will work in Drupal 5 as well. Again, this solution works only for PHPTemplate-powered themes.
You need to provide the machine-readable names for content types you wish to exclude, because $node->type is used in the condition, and it is the machine-readable name for the content type. Why are we comparing machine-readable names? Simply to avoid database queries. There is one database query we cannot avoid in our solution, it is the one query we execute to print the human-readable name for the content type.
Possible variations: place the content type information somewhere else in the node; display the content type information only in the teaser; etc.
Comments
Great
php code can sometimes be confusing This is well laid out thanks !!!! Wonderful information Please keep blogging!
Thank you for useful
Thank you for useful information. blood diamonds I'm starting to explore this area and your blog - one of my most favorite!
This is really good info. I
This is really good info. I can see lots of tips here explained in detail. I wish i landed here early. Anyways it's great to be here to get these updates.
Thanks again to the
Thanks again to the organizers and if I can do next time? I think the other perl hackers who had felt the same way as we'll be there for a value of "us" and we hope that you will be happy to have us.
bandages
Thanks!
Thanks for this tip, it helped a lot. Personally I would add a hook_node() method to add this information to the $node object. And, better yet, I think the "readable name" of a node should be there by default (maybe in Drupal 8?) since the "type" is - but it seems counterintuitive to have to call a separate method just to get the readable name of a node's type.
Thank you for useful
Thank you for useful information. I'm starting to explore this area and your blog - one of my most favorite!
This was a useful post and I
This was a useful post and I think it is rather easy to see from the other comments as well that this post is well written and useful. I bookmarked this blog a while ago because of the useful content and I am never being disappointed. Keep up the good work .how to repair ps3
I agree with the entire
I agree with the entire comment above. Thanks for sharing nice information with us. i like your post and all you share with us is up todate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job.
ingersoll rand air compressor | husky air compressor.
http://www.cocktaildresseshome.com/junior-cocktail-dresses_c11
Cocktail dresses for juniors should be stylish, trendy and elegant. Take action immediately! Choose your dream junior cocktail dresses.
Re:
Thanks for sharing this valuable piece of information with us. I am glad to find this stuff here. Keep up the good work. power scooters
ta, node_get_types() was
ta, node_get_types() was what i needed!
Thank you for the code, your
Thank you for the code, your solution is brilliant. Great coding. does nono work
I was just looking for any
I was just looking for any information of how I could print the content type name along with the “submitted” info. This article literally spells out everything on the subject and with the code and simple explanations; it was a pleasure to read it up!! This is really going to help my work so much easier and help me do the job with any further searching on the web!!
Nice Post, Caroline. In
Nice Post, Caroline. In Drupal 7, however, I could not get this to work. Looks like there's been a change in the API.
So for those who may be interested, here's the code that worked for me with D7:
<?php print node_type_get_type ($node) -> name; ?>
Many thanks again !
I agree with the entire
I agree with the entire comment above. Thanks for sharing nice information with us. i like your post and all you share with us is up todate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job.
Post new comment