开发者

Reuse Variable across Wordpress Templates

开发者 https://www.devze.com 2023-01-15 07:35 出处:网络
I query some information in my wordpress blog\'s header. 开发者_运维问答How can I reuse the variable say in the sidebar of the blog?

I query some information in my wordpress blog's header. 开发者_运维问答How can I reuse the variable say in the sidebar of the blog?

If I try something like this in the sidebar, the output stays blank:

<?php if(isset($my_header_variable)) echo $my_header_variable; ?>


Just make the variable GLOBAL and it will be available.

1) In your header.php:

<?php
$GLOBALS['skt'] = 44;
?>

2) In your sidebar.php:

<?php
echo $GLOBALS['skt'];
?>

And the value 44 will be correctly displayed. I use this way and it works fine for me.


If the value is not going to change you can use define

 define("MY_VAR", "something");

Then to access later on

 if(defined("MY_VAR"))
      echo MY_VAR; // Will echo 'something'
0

精彩评论

暂无评论...
验证码 换一张
取 消