繁体   English   中英

声明全局变量php(wordpress)

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM