通常Drupal主题会显示文章的创建日期,以及作者信息。同时创建日期和作者是放在一个主题变量$submitted里面的。有时候我们只需要显示日期而不想显示作者信息,因为对大多数Drupal网站来说,通常是个人博客或个人站点,而账号就是admin,没有必要显示这个作者信息。
通常Drupal主题会显示文章的创建日期,以及作者信息。同时创建日期和作者是放在一个主题变量$submitted里面的。有时候我们只需要显示日期而不想显示作者信息,因为对大多数Drupal网站来说,通常是个人博客或个人站点,而账号就是admin,没有必要显示这个作者信息。
自定义Drupal日期显示方法:
我们可以通过编辑Drupal主题的node.tpl.php文件来实现这个功能。在这个文件中,你可以查找$submitted来定位需要修改的内容,通常你会在node.tpl.php中看到类似下面的代码:
<div class="submitted"><?php print $submitted; ?></div>
这行php代码的作用就是显示Drupal节点日期和作者的信息。我们可以将上面的代码替换为下面这样:
<div class="submitted"><?php print t(‘Posted ‘) . format_date($node->created, ‘custom’, "F jS, Y") . t(‘ by ‘) . theme(‘username’, $node); ?></div>
这样就把Drupal节点创建日期和作者信息分开来了,如果你不需要显示作者信息,就把“ . t(‘ by ‘) . theme(‘username’, $node); ?>”从代码中去掉既可以了。
更多日期格式:
你可以自定义日期显示格式"F jS, Y",这个是php的日期格式。有下面的一些格式可以选择:
a – "am" or "pm"
A – "AM" or "PM"
d – day of the month, 2 digits with leading zeros; i.e. "01" to "31"
D – day of the week, textual, 3 letters; i.e. "Fri"
F – month, textual, long; i.e. "January"
h – hour, 12-hour format; i.e. "01" to "12"
H – hour, 24-hour format; i.e. "00" to "23"
g – hour, 12-hour format without leading zeros; i.e. "1" to "12"
G – hour, 24-hour format without leading zeros; i.e. "0" to "23"
i – minutes; i.e. "00" to "59" j – day of the month without leading zeros; i.e. "1" to "31"
l (lowercase ‘L’) – day of the week, textual, long; i.e. "Friday"
L – boolean for whether it is a leap year; i.e. "0" or "1"
m – month; i.e. "01" to "12"
n – month without leading zeros; i.e. "1" to "12"
M – month, textual, 3 letters; i.e. "Jan" s – seconds; i.e. "00" to "59"
S – English ordinal suffix, textual, 2 characters; i.e. "th", "nd"
t – number of days in the given month; i.e. "28" to "31"
U – seconds since the epoch
w – day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday)
Y – year, 4 digits; i.e. "1999" y – year, 2 digits; i.e. "99"
z – day of the year; i.e. "0" to "365"
Z – timezone offset in seconds (i.e. "-43200" to "43200")
参考资料:
- http://drupal.org/node/121823
- http://cn2.php.net/manual/en/function.date.php
- http://www.topnotchthemes.com/handbook/author-date-display