[英]Declaring global variable php (wordpress)
在wordpress functions.php
文件中,我使用了以下变量:
$MediSHOP_settings_db_theme = (get_option("MediSHOP_settings"));
但是,当我尝试在footer.php
回显它时,没有显示任何内容:
<?php echo $MediSHOP_settings_db_theme['shoptel']; ?>
除非我在footer.php中声明为全局
有没有办法使该变量持久化,所以我不必在header.php,footer.php和index.php及其他模板文件中将这个变量声明为全局变量?
您可以在class
包装类似这样的重要内容。 因此,尽快声明此var,也许是在init
钩子上声明:
$this->MediSHOP_settings_db_theme = (get_option("MediSHOP_settings"));
可以轻松地在footer.php中使用
<?php $this->MediSHOP_settings_db_theme: ?>
推荐tut: http : //wp.tutsplus.com/tutorials/a-beginners-oop-class-framework/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.