【问题标题】:How do I override "Submitted by" text for Drupal nodes?如何覆盖 Drupal 节点的“提交者”文本?
【发布时间】:2011-08-27 14:45:03
【问题描述】:

我正在使用 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),
    ));
}

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

或者,更简单的是,有没有一种管理方法可以删除节点页面中的提交设置?

【问题讨论】:

    标签: drupal drupal-6


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      如果您想根据某些标准更改字符串,并根据内容使用(例如)不同的字符串,那么您可以更改 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';
        }
      }
      

      如果您只想使用不同的字符串,而不是“由 !username on @datetime 提交”,则有更简单的替代方法:

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

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

      第二种方法的优点是不需要使用其他模块,但是需要修改settings.php,不像第一种方法那么容易。

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

      【讨论】:

        【解决方案3】:

        两种方式

        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

        【讨论】:

          【解决方案4】:

          这可能应该在drupal上。*?

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-05-09
            • 1970-01-01
            相关资源
            最近更新 更多