i've been having a nightmare trying to understand the Drupal way! I have an example here and if someone could show me the correct way to achieve my result I'm hoping it will help me open the door to understanding.
So I'm trying to alter the Node creation Date to appear similar to Stack Overflows format. E.G. This is either "Posted x hours ago" or "Posted on 17th Aug at 12:22" etc.
I have managed to create the desiered effect using the "node.tpl.php" file. I've achieved this using the node variable "$created" and the following code.
$showCreate = round((time() - $created) / 60);
if ($showCreate < 60) {
$showCreate = $showCreate . "mins ago." ;
} else {
$showCreate = round($showCreate / 60);
if ($showCreate > 24) {
$createMonth = format_date($created, 'custom', 'M');
$createDate = format_date($created, 'custom', 'd');
$createTime = format_date($created, 'custom', 'H:i');
switch ($createDate) {
case 1:
case 21:
case 31:
$createDate = $createDate . "st";
break;
case 2:
case 22:
$createDate = $createDate . "nd";
break;
case 3:
case 23:
$createDate = $createDate . "rd";
break;
default:
$createDate = $createDate . "th";
break;
}
$showCreate = $createMonth . " " . $createDate . " at " . $createTime;
} else {
$showCreate = $showCreate . "hrs ago." ;
}
}
Is this a 'correct' way to achieve this? or would you use some of the hooks and preprocess functions? I would prefer to wrap this up into a MOdule so I can apply it directly to my other drupal sites.
Thanks a lot in advance.