Drupal tip: Simple author/date/comment display

It's the little details that make the difference in a clunky design and one that communicates with brevity and elegance. One thing that I've always hated in my Drupal blog is the wordiness of my author/date/comment line. You know what I'm talking about. In node.tpl.php it's the stuff you get when you print out $links.

Well, I resolved to make things cleaner in the next blog theme I work on, so that I can get displays more like this:

By jibbajabba on 21 Feb | 1 comment

Rather than this:

February 21, 2007 - 10:06am
jibbajabba's blog | 1 comment

I know it seems like such a minor thing, but it's little things like wanting to change that, but being too lazy to go figure out how to do it that keep me using the default display in my themes. Well, no more. On the bike blog (Love & Sprockets) I'm going to do it this way:

By <?php print $name; ?> on <?php print format_date($node->created, 'custom', 'd M'); ?> |
<?php
 
print $comment_count . ' comment';
  if (
$comment_count != 1) { print 's'; }
?>

Or using the format_plural function, which chx pointed out:

By <?php print $name; ?> on <?php print format_date($node->created, 'custom', 'd M'); ?> |
<?php print format_plural($comment_count, '1 comment', '@count comments'); ?>

Ahhh. I feel better now.

Comments

01 Paul
02/22/07 @ 20:23

Agreed. After working with Drupal a ton I think the hardest thing about it is the styling.

02 Lync
02/22/07 @ 23:11

I just want to say that the theme of loveandsprockets.com is fantastic. Did you start that theme from scratch?

Advertisement
03 jibbajabba
02/23/07 @ 08:47

@Lync: Thanks! Yes, it's a PHP Template theme that I designed.

04 chx
02/23/07 @ 20:24

I advise looking at format_plural, format_plural($comment_count, '1 comment', '@count comments') -- this is shorter and translateable while at it. A template written for any recent Drupal version (4.7+) does not need $node-> in templates, I think.

05 jibbajabba
02/24/07 @ 07:15

Thanks, chx. That's much cleaner.

06 phin
02/26/07 @ 01:18

Do you know if this works with Drupal 5.1?

I tried it (and a couple of variations) and it looks like the comment_count variable is dead, or maybe it's just my install.

07 Frank
02/26/07 @ 05:50

Yes, you are right. The display of author and date looks much better this way. Now it is reduced to the real important parameters.

08 Bridgestone Journo
03/01/07 @ 11:39

There are lots of variations to reduce text, but leave all information

09 Markus
04/22/07 @ 12:49

Looks better now.
These little details are easily configured in Drupal so it's not a problem :)

10 themegarden.org
05/26/07 @ 14:20

Have you enabled the comment module.
As I know, the comment module is "responsible" for this.

Advertisement
11 月餅
08/09/07 @ 04:27

I tried it (and a couple of variations) and it looks like the comment_count variable is dead, or maybe it's just my install.

12 Parfümök
09/05/07 @ 16:53

And we the situation, if my skin is .theme?

13 jibbajabba
09/05/07 @ 17:43

Sorry, can't help you there. I'd ask your question on drupal.org in the theme section.

14 WAN
01/21/08 @ 00:08

Good stuff! I love Drupal.

Justin

15 Ann
02/26/08 @ 10:42

Actually, drupal is the best cms out there.

16 Jhn
02/27/08 @ 09:25

Hi,

Pardon my ignorance, i see drupal sites looking like typical wordpress blogs. Drupal users however swear that it is superior. Care to enlightenment me?

Thanks.

17 jibbajabba
02/27/08 @ 11:03

It really depends on what your needs are. If you want a simple blog, Wordpress may work for you. If you want more, then you have to do your research. There are a lot of articles and blog entries out there that will give you all the info you need to do a comparison, but it really comes down to requirements.

Google Drupal vs. WordPress

This site is really just a simple blog. But what makes it different, in my opinion, is how I handle sections and do classification of content. I wouldn't be able to do a lot of the classification / tagging of content I do here on a WordPress blog. I have deployed several WordPress sites for clients, and it really comes down to what your needs are.

18 Robert
03/28/08 @ 20:08

Thanks a lot, I searched on drupal.org and searched and tried and tried. Hours now. I should have found this post earlier.

19 jln
04/27/08 @ 17:36

From my experience in drupal 5, the date is showm when $submitted is printed by PHP -- Not $links.

Maybe you could edit your post to reflect that, could be confusing for newbies.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <strong> <dd> <dl> <dt> <i> <li> <ol> <u> <ul> <code> <blockquote> <fieldset> <legend> <h6> <span> <img> <div> <p>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options