zen子主题函数覆写

论坛: 
template.php,通过这个文件你可以定义主题函数

template.php 新添加或覆写函数,在主题开发设置中勾选: 在所有页面重建主题注册信息,可以及时得到所需的效果。如果不开启则需要清除缓存等。

template.php中加上:
function ***_preprocess_comment(&$variables, $hook) {
  $variables['username'] = t('!username', array('!username' => $variables['author'], '!datetime' => $variables['pubdate']));
  $variables['usertime'] = t('!username replied on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['pubdate']));
生效后直接可以在模板上贴以下简洁代码,drupal是不是做模板更方便了!
<div><?php print $picture; ?></div>
 <div><?php print $username; ?></div>
在node.tpl.php文件中有很多的PHP变量。比如,你可以用$user_picture变量来输出节点创建者的用户头像。在比如,你也可以非常轻易的用$name变量来输出节点创建者的名字。下面这样的语句是另一个有趣的函数(或者叫方法): 
hide($content['comments']); 
这个语句的作用是通过调用hide()方法来欺骗drupal_render(),让它以为括号内的东西已经被渲染过了。其实根本就没有执行渲染,也就是说并没有将$content['comments'] 转化为HTML代码。因此在渲染$content数组的时候就会直接忽略掉数组中的comments。(晴空注:这里之所以要将comments隐藏起来,是为了让它和内容出现在不同的Div中,这样就可以用不到的Css类名分别为他们设定样式。)
 
因此,当内容(除了Link和Comment)渲染完成后,又紧接着对刚才隐藏的元素进行了渲染: 
<?php print render($content['comments']); ?> 
这样做就可以对内容和评论以及链接分开进行渲染。