du6jws6975 2015-11-22 13:25
浏览 67
已采纳

wordpress插入php解析错误

It does not work because the second block does not know what $out is. I did not find how I can handle

[insert_php]
/* do something */
$out = smthing;
[/insert_php]

<html>
/*something */    

[insert_php]
echo $out;
[/insert_php]
</html>

Edit: How can I write a for loop, it did not work

[insert_php]foreach($elements as $element){ [/insert_php]
<label class="radio-inline"><input type="radio" name="opt" value=[insert_php]echo $element; [/insert_php] > [insert_php] echo $element; [/insert_php]</input> </label>
[insert_php]}[/insert_php]
  • 写回答

1条回答 默认 最新

  • dongtuo2373 2015-11-22 13:38
    关注

    The [insert_php]...[/insert_php] shortcodes are totally separate from each other. The entire body of that tag must be complete and valid PHP code.

    You can share the variable by using a global variable. I'd pick a name that's more unique than $out, to be on the safe side:

    [insert_php]
    global $MY_CUSTOM_TEMP_VAR;   
    /* do something */
    $MY_CUSTOM_TEMP_VAR = smthing;
    [/insert_php]
    
    <html>
    /*something */    
    
    [insert_php]
    global $MY_CUSTOM_TEMP_VAR;  
    echo $MY_CUSTOM_TEMP_VAR;
    [/insert_php]
    </html>
    

    You can make a loop inside a single [insert_php]...[/insert_php] shortcode tag:

    [insert_php]
    foreach($elements as $element)
        echo "
           <label class='radio-inline'>
             <input type='radio' name='opt' value='" . esc_attr( $element ) ."'>$element</input>
           </label>
        ";
    [/insert_php]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!