• Resolved estr

    (@estr)


    Hello,

    If someone could answer that. I have the following code:

    =================================
    <?php if (is_single()) { ?>

    <p>Random text that will be different for each post.</p>

    <?php } ?>
    =================================

    Is it somehow possible with this plugin for the random text that I want to be displayed, to be specified in the post itself? Because creating a unique snippet per post is excessive.

    Thank you!

    http://wordpress.org/plugins/php-code-for-posts/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter estr

    (@estr)

    Tried to put “<?php if (is_single()) { ?>” into [php snippet=1].

    And “<?php } ?>” into [php snippet=2].

    And then to do the following in the post:

    [php snippet=1]
    <p>Random text that will be different for each post.</p>
    [php snippet=2]

    But this does not work 🙁

    Thread Starter estr

    (@estr)

    In the plugin description it is said that:

    “The plugin also contains a variable array which you can add variables to for use between snippets called $_var and is available though the global variable $PHPPC which is an object, so its $PHPPC->_vars[]”

    But I am not that advanced to understand how to use this or if this could be used to solve my problem at all.

    Plugin Author Jamie

    (@themissingcode)

    Hi Estr,

    as of version 1.1.1 you can now specify parameters to the plugin’s shortcode using the parameter “param”.

    you can specify the value of param in a name=value pair separated by &s.

    For example [php snippet=2 param="myvar=myval&othervar=otherval"].

    There parameters can be accessed within your snippet using $_parameters variable.

    for example: echo $_parameters["myvar"]; would output “myval”

    I hope this solves your issue.

    Thanks,
    TMC

    Thread Starter estr

    (@estr)

    Great, thank you!

    I have a similar question, but I need to insert a [shortcode] that calls a db field as my parameter/variable…

    I’m not super great at php, so I may not be defining the parameters/variables within the php correctly…

    In the snippet I have…

    <?php

    echo shortenURL(‘http://aq155.nuteam.com/go/Opp/$_myvar&#8217;);
    ?>

    then when I use the short code, I need the myvar = [iw_db_AffiliateID]

    something like:

    [php snippet=1 param=”myvar=[iw_db_db_AffiliateID]”

    So, 2 questions…

    1. how do I define “myvar” within the snippet to be a parameter/variable

    2. Can I Use a shortcode/db field as the variable, and if so, how do I specify it in there?

    Any help would be greatly appreciated by this newbie..

    Thanks.

    nevermind…figured it out. thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Variable text between PHP code’ is closed to new replies.