我有一个Wordpress父主题,我的子主题扩展了很多功能。我的问题是,当我想要在我的子主题文件夹结构中使用或扩展来自父文件夹的类时,我得到错误"class is not defined“或"class not found”。
使用父主题中的类的正确方法是什么?
下面是其中一个类的示例:
class MyNewClass extends ReadAndDigestWidget {} 这个类将在其中调用更多来自父主题的类。
如果能帮助我们更深入地理解Wordpress和php,我们将不胜感激!
发布于 2017-01-07 04:51:35
PHP在设计上不是一种OOP语言,因此其结果有时可能微不足道。以下是PHP中继承如何工作的基本示例
class ChildTheme extends ParentTheme {
function parentDropDownMenu(){
parent::dropDownMenu();
//do additionall stuff
}
}
theme = new ParentTheme();
$theme->dropDownMenu(); // will call the parent function directly
$theme->parentDropDownMenu(); // will call the function override通常,我甚至不会在PHP中重写父类的类方法,而只是在无法完全控制父类的情况下扩展类。如果在wordpress中进行升级,而你覆盖了一个必须进行的升级,该怎么办?
https://stackoverflow.com/questions/41513994
复制相似问题