views:

16

answers:

2

Hi,

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; ?>
A: 

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'
jakenoble
There is a typo in your `if` statement.
shamittomar
@shamittomar - thanks. Fixed.
jakenoble
+1  A: 

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.

shamittomar