PHP Code for posts
[resolved] Variable text between PHP code (7 posts)

  1. estr
    Posted 2 years ago #


    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!


  2. estr
    Posted 2 years ago #

    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 :(

  3. estr
    Posted 2 years ago #

    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.

  4. Jamie
    Plugin Author

    Posted 2 years ago #

    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.


  5. estr
    Posted 2 years ago #

    Great, thank you!

  6. nuteamfreedom
    Posted 2 years ago #

    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...


    echo shortenURL('http://aq155.nuteam.com/go/Opp/$_myvar');

    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..


  7. nuteamfreedom
    Posted 2 years ago #

    nevermind...figured it out. thanks.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • PHP Code for posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.