2011-08-27 73 views
0

我使用Drupal的6如何覆盖Drupal节点的“提交”文本?

在./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), 
    )); 
} 

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

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

回答

1

当你只是想删除的文字,那么你可以说Drupal的不显示信息:进入管理/建设/主题/设置,并取消选择您不想要的内容类型显示该字符串。在屏幕截图中,“页面”内容类型没有显示“提交者”信息,但显示其他内容类型。

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用户名提交! ,“有更容易的选择:

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

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

第二种方法的好处在于,你并不需要使用另一个模块,但你需要改变的settings.php,这是不是与第一种方法一样容易。

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

1

2种方式

1:_node_subbmitted在你的template.php就把[THEME_NAME]()

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), 
    )); 
} 

模板当然是更简单的方法

这里是exacly你怎么能做到这一点http://drupal.org/node/11811

2

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