WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. estr
    Member
    Posted 7 months ago #

    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/

  2. estr
    Member
    Posted 7 months 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
    Member
    Posted 7 months 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. The.Missing.Code
    Member
    Plugin Author

    Posted 6 months 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.

    Thanks,
    TMC

  5. estr
    Member
    Posted 6 months ago #

    Great, thank you!

  6. nuteamfreedom
    Member
    Posted 2 months 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...

    <?php

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

    Thanks.

  7. nuteamfreedom
    Member
    Posted 2 months ago #

    nevermind...figured it out. thanks.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.