tags:

views:

162

answers:

2

I wrote my own custom page template for my Wordpress page, now I want to change sidebar.php to insert a small menu whenever that page template is loaded.

// sidebar.php
if ( isset($event_name) ) {
  // do something
}

But apparently sidebar.php doesn't recognize variable $event_name.

How do I come about solving this?

+2  A: 

While I'm not familiar with the way WordPress implements templates, have you tried declaring the variable global in the sidebar page?

Tim Lytle
This is correct. I'm assuming you're using get_sidebar to retrieve your sidebar. The scope is different inside of get_sidebar then in your page template so you need to globalize your variable.
nickohrn
I saw they used a function to get the sidebar and guessed the rest. So the master template is really just in the global namespace?
Tim Lytle
I totally forget about globalize the variable. besides I combine this with is_page_template and it works beautifully!
huy
+1  A: 

See: Function Reference/is page template « WordPress Codex to be able to detect page template in use.

songdogtech