Problems with Wordpress templates

They have: 173 posts

Joined: Feb 2005

I posted this in wordpress forums but got no bite...

I tried to modify the header.php file for the template to just require() my global header for my site.

Two issues I noticed right away were:
I use $sql for the link to MySQL... I see Wordpress uses it to hold the queries. What can I do?

I also had some issues with scope, where declared variables in MY header.php file were not available through $GLOBALS['var_name']

Any input, any ideas?

Thanks!

SonicMailer Pro - Professional mailing list manager & award-winning email marketing software
Download a FREE 30-day trial today!
Use coupon savemoreon4 and save 10%!

DDoSAttack's picture

He has: 38 posts

Joined: Oct 2006

For the $sql problem I would just use something different like $sql1 or something. It is easier to alter your code then it is to alter their code.

If it is not in $GLOBALS then it is not in the scope. Is your variable that you are trying to find inside of a function or a class?

They have: 173 posts

Joined: Feb 2005

DDoSAttack;210714 wrote: For the $sql problem I would just use something different like $sql1 or something. It is easier to alter your code then it is to alter their code.

If it is not in $GLOBALS then it is not in the scope. Is your variable that you are trying to find inside of a function or a class?

Nope - its just in an init.php page called from header.

Works for my entire site, but not when it is called from within the header.php template in wordpress. My best guess is that it is wrapped in a function/class/something, but surely there is some way to "get around" this?

SonicMailer Pro - Professional mailing list manager & award-winning email marketing software
Download a FREE 30-day trial today!
Use coupon savemoreon4 and save 10%!

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

To avoid namespace clashes, prefix your global variables with an uncommon string. You might rename your [incode]$sql[/incode] to [incode]$triexa_sql[/incode], for example. [incode]$sql1[/incode] isn't meaningful and might cause problems later. Smiling

To ensure variables are in the global namespace, refer to them by [incode]$GLOBALS['var'][/incode], even when assigning. If you still can't see the variable from elsewhere, it's possible you're looking for it before it has been created. Check the order of execution, you might be able to fix it by promoting a call to require or something.

Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.