如何覆盖Drupal节点的“Submitted by”文本?

时间:2011-08-27 14:45:03

标签: drupal drupal-6

我正在使用Drupal 6.

在./modules/node/node.module中,以下内容在节点视图中输出提交信息:

/**
 * Format the "Submitted by username on date/time" for each node
 *
 * @ingroup themeable
 */
function theme_node_submitted($node) {
  return t('Submitted by !username on @datetime',
    array(
      '!username' => theme('username', $node),
      '@datetime' => format_date($node->created),
    ));
}

显然我不想改变核心模块的代码,所以我想我要做的是创建一个新模块,通过返回一个空字符串简单地覆盖这个函数。我该怎么做?

或者,更简单的是,是否有管理方法来删除节点页面中的提交设置?

4 个答案:

答案 0 :(得分:2)

如果您只是不希望它显示在节点视图中,则可以根据内容类型以管理方式删除它。例如,您可以为内容类型“产品”或“合作伙伴”禁用它,但将其保留为内容类型“博客帖子”。这个选项可以在admin / build / themes / settings中找到,它叫做“显示帖子信息”

答案 1 :(得分:1)

2种方式

1:在你的template.php中输入[theme_name] _node_subbmitted()

function [your_theme_name]_node_submitted($node) {
  return t('blah blah !username on @datetime',
    array(
      '!username' => theme('username', $node),
      '@datetime' => format_date($node->created),
    ));
}

2或在您的模块中

function [your_module_name]_node_submitted($node) {
  return t('blah blah by !username on @datetime',
    array(
      '!username' => theme('username', $node),
      '@datetime' => format_date($node->created),
    ));
}
模板中的

当然更简单

这里有你怎么做http://drupal.org/node/11811

答案 2 :(得分:1)

由于您只想删除该文本,因此您可以告诉Drupal不要显示该信息:转到admin / build / themes / settings,并取消选择您不想显示的内容类型那个字符串。在屏幕截图中,“提交者”信息未显示“页面”内容类型,但显示的是其他内容类型。

screenshot

如果您想根据某些条件更改字符串,并根据内容使用(例如)不同的字符串,那么您可以更改Drupal(或任何模块)调用theme("node_submitted", $node)时调用的主题函数,这意味着您需要使用类似于以下代码的代码来实现hook_theme_registry_alter()

function mymodule_theme_registry_alter(&$theme_registry) {
  if (isset($theme_registry['node_submitted'])) {
    $theme_registry['node_submitted']['function'] = 'theme_mymodule_node_submitted';
  }
}

如果你只想使用另一个字符串,那么总是使用它而不是“在@datetime上提交!用户名”,有更简单的选择:

  • 使用String Overrides模块,您可以将模块传递给t()的任何字符串替换为您喜欢的另一个字符串。
  • 在settings.php中添加以下代码可以获得相同的结果。

    $conf['locale_custom_strings_en'] = array(
      'Submitted by !username on @datetime' => 'The string you want to use',
    );
    

第二种方法的专家是你不需要使用另一个模块,但你需要改变settings.php,这不像第一种方法那么容易。

在主题中使用主题功能和使用模块之间,我宁愿使用模块,因为它不需要更改使用过的主题;在用户能够为自己设置主题的情况下,这意味着不改变所有可选主题。另一个专业是,如果你想使用原始字符串,你只需要禁用该模块。

答案 3 :(得分:0)

这可能应该是drupal。*?

http://drupal.org/project/submitted_by是一种替代解决方案,并非所有主题都会尊重上述覆盖,至少在D6中不会。