Assigning Template Variable from a Post?
-
Hey all, I looked around briefly but couldn’t find a lot of information that would help me out. I’m building a custom content-single.php, and I’d like for it to be a template that uses php variables that will eventually be called from a SQL database. For now though, I’d like to assign the variables in the_content() if possible.
I have the ‘PHP Exec’ plugin installed, which allows php to be inserted in posts between
<phpcode>
tags, and it seems to be working fine.As a test, I initialized a test variable on the actual content-single.php above the call for the_content() with
<php $address = 'default'; ?>
then in the actual wordpress content editor, i’ve written
<phpcode> <?php $address = 'success'; ?> </phpcode>
back to content-single.php, after the template calls the_content(), I’ve got
<?php echo $address; ?>
which is returning “default” on the actual page.
So with a little bit of research, it looks like a problem of the variable’s scope because I’m assigning it within a function. Do I use globals here? I’m not sure exactly how to proceed, any advice would be appreciated.
- The topic ‘Assigning Template Variable from a Post?’ is closed to new replies.