自定义模块将是一个很好的方法,因为它在主题图层之前加载,并且可以从Drupal中的几乎任何地方访问,除了其他模块的权重低于自定义模块。钩子和其他覆盖物也可能派上用场。
但是,如果你必须在主题层中有它,另一种选择是将它添加到你的主题的template.php,它应该可以在page.tpl.php等内部使用,但不是我不相信的块。
/sites/all/modules/mymodule/mymodule.info
name = My Module
package = !
description = It is MY module, not yours!
core = 6.x
包 “!”将使这个模块出现在模块页面顶部
/sites/all/modules/mymodule/mymodule.module
<?php
// Load mymodule.morePHP.inc
module_load_include('inc', 'mymodule', 'mymodule.morePHP');
// A custom function
function mymodule_my_custom_function($args) {
/* do custom stuff here */
return 'output';
}
/sites/all/modules/mymodule/mymodule.morePHP.inc
<?php
// An included custom function
function mymodule_other_custom_stuff() {
}
另一种可能性是直接使用标准php语句“include_once”。 –
感谢您的回答,但我已将此文件放在根文件夹中。我尝试过使用module_load_include()函数,但我无法正确使用此功能。我遇到致命错误:无法重新声明该函数。 –
该错误意味着函数名已被使用,可能是您添加的[两个]。因此,删除函数定义的一个实例或使用不同的函数名称。 –