弄过drupal的,对blog中的submitted都不会太陌生吧,Submitted by admin on Tue, 04/12/2011 – 11:54这是其默认的一种风格,今天我们只要来看如何在drupal7中改写这种风格。; P8 ^; v0 f6 C4 |, D' f3 S5 e
首先我们来看看在drupal6中的实现方法:
& Q! O( }: c) g$ J3 @! X X! E- ~7 I+ S5 J5 ~* O+ p" B3 Y* l
1、在相应的主题下,加上下面的代码; V7 e1 K6 \9 @- h- M8 I( |
function yourthemename_node_submitted($node) {return t('Posted by !username on @datetime', array('!username' => theme('username', $node),'@datetime' => format_date($node->created, 'custom', 'd M Y')));}6 o4 n: w2 |2 Q* w
& |! G a4 f0 p3 v. j0 a
2、然后在node.tpl.php文件中加入) x* n) Q1 V5 L
<?php if ($display_submitted): ?> <?php print $submitted ?><?php endif; ?>
' L( h3 }4 J0 U 清除缓存就能看到改过后的效果了。
9 X+ A! @# g& C 上面是在drupal6下的修改方法,而我们今天的主题是如何在drupal7下改写。有人会说,就按上面那种方法不行吧,在我试过之后,是没有任何效果的,后来经查询才得知,在drupal7下好像是不存在这个么下theme_node_submitted()函数。如此下来我们为了要得到效果就需要通过其他的方法。现在我总罗列几种修改的方法
& }! t& j, ^4 l1 Z: p4 m( z1 r2 \# @) O1 F$ r9 _7 O# D
第一种方法:% s4 H7 r7 }) X9 h" P, v* ?- E+ S
我们在相应主题下的template.php下加入下面的代码, S' q, H. l: r5 D y; k {
function html5_preprocess_node(&$variables) { $variables['submitted'] = t('By !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));}
; I3 {- j% ^+ z. p! U 加完之后同样需要在node.tpl.php下加入" T2 G g& q7 Y2 t: i! C s
<?php if ($display_submitted): ?> <?php print $submitted ?><?php endif; ?>3 S( Z5 m6 W- W+ Z
这样才能显示出来的。) @2 r, z! ^ `
+ U& n8 N' i8 d2 H( |5 `第二种方法:% M" B. u' S* Y+ n& s/ L; G* ]$ C
直接在node.tpl.php下修改。也就是在node.tpl.php文件中加入
; P% F a% v- F! {& S) s<?php if ($display_submitted): ?> <footer class="author"> <?php print t('By !username on !datetime', array('!username' => $name, '!datetime' => format_date($node->created))); ?> </footer><?php endif; ?>+ F: |% s: g3 v4 w$ ]2 ]
如果还想修改日期格式,我们可以把代码换成
* d. Z% t9 a" ]) y- a' M# ^<?php print t('By !username on !datetime', array('!username' => $name, '!datetime' => format_date($node->created, 'custom', 'd M Y')));?>! n1 E8 M0 _* X* a. ?& y+ _( z% q
& ~, L/ Z& Y; O1 g第三种方法:. f0 k. W9 K# U- s: q! l' L$ t1 [
这种方法和第二种是一样的,只是我们把上面的分成了两部分,有时为了更好的布局,所以我现在拆开来放
7 U/ w; a" Y# c% l. e5 {4 w<?php if ($display_submitted): ?> <footer class="author"> <div class="username"> <?php print t('By !username',array('!username'=> $name)); ?> </div> <div class="date"> <?php print t('on !datetime',array('!datetime'=>format_date($node->created, 'custom', 'Md, Y'))); ?> </div> </footer><?php endif; ?>
! r, K1 z5 w+ ^' n% S) i! [6 H. F: S4 \9 }2 ?) b$ i) z
: ]3 Y2 f# }. T- d7 R; X
如需转载请注明出处:W3CPLUS2 j! u3 d, R* x8 j2 Y2 t# y
0 `1 A+ l" {$ g+ a9 S3 `: h* b
|
|