• I’ve been searching everywhere for an answer to this question but so far I’v only got as far as to the RunPHP plugin (http://dev.wp-plugins.org/wiki/RunPHP).

    That plugin lets me execute php code in my posts but wont except a variable that has been defined in the template code. Defining it inside the post doesn’t help either (probably cause it is checking a cookie for a value).

    Has anyone been able to do this successfully? I would really like to have this one solved. Most of my site is dependent on it 🙂

Viewing 1 replies (of 1 total)
  • Thread Starter fredrik

    (@fredrik)

    Don’t worry about this one. Found a solution in the combination PHP Exec plugin and defining the variable inside the post. Like so:

    <phpcode>
    <?php // Get current style id from cookie
    $style = $_COOKIE['style'];
    If($style == "1") { $bgc = 'dbg'; }
    elseIf($style == "2") { $bgc = 'lbg'; }
    else $bgc = 'dbg';
    ?>
    </phpcode>

    Post content text and so on here…

    <img src="/wp-content/<phpcode><?php echo $bgc; ?></phpcode>/test-work.jpg"> (..and the echoing the variable )

    Beautiful!

Viewing 1 replies (of 1 total)

The topic ‘Using a php variable in posts?’ is closed to new replies.