0
我希望上传文件的标题根据节点类型显示不同的文本。我重写了将其复制到我的主题的template.php文件中的核心函数,并将其重命名为phptemplate_upload_attachments。
<?php
function phptemplate_upload_attachments($files) {
global $node;
$header = array(t('Default text'), t('Size'));
if ($node->type == 'orange') {
$header = array(t('ORANGE CUSTOM TEXT'), t('Size'));
}
$rows = array();
foreach($files as $file) {
$file = (object)$file;
if ($file->list && empty($file->remove)) {
$href = file_create_url($file->filepath);
$text = $file->description ? $file->description : $file->filename;
$rows[] = array(l($text, $href), format_size($file->filesize));
}
}
if (count($rows)) {
return theme('table', $header, $rows, array('id' => 'attachments'));
}
}
?>
正如你所猜测的,我只添加了橙色节点类型的行,但它不起作用。我知道这个函数是正确的,因为我测试了它改变默认文本。另外,我清除了缓存,并尝试添加全局$节点。
为什么这不起作用?
这是应该做什么?使$节点可用? – 2011-02-23 17:37:01
是的,但我想知道如果arg(1)在主题函数中可用,但可能你可以在$ files变量中找到nid – Michal 2011-02-23 17:38:34
它的工作原理!谢谢。小心解释这是如何或为什么会起作用? – 2011-02-23 17:49:49