• Hello! I’m trying to make a test in a post, but I get the message:

    “PHP Parse error: syntax error, unexpected T_VARIABLE in E:\home\barreirainformatica\Web\novo\wp-content\plugins\insert-php\insert_php.php(48) : eval()’d code on line 11”

    Did I type something wrong? I’m not yet used to PHP anyway.
    This is what I’m trying to do:

    [insert_php]
    
    $time = date("H"); 
    
    if( $time >= 17 && $time < 19 )
    
        $img_name = 'http://www.bistec.com.br/novo/wp-content/uploads/2014/11/Sweda-Apas-g-2010-shop_166110151912930.jpg';
    
    else( $time >= 19 && $time < 6 )
    
        $img_name = 'http://www.bistec.com.br/novo/wp-content/uploads/2014/11/padarias560.jpg';
    
    [/insert_php]
    
    <style>
        .my-class{background-image:url('[insert_php] echo $img_name; [/insert_php]');}
    </style>
    
    <div class="my-class">Aproveite que o S@T Sweda - Soluções em Automação Comercial foi homologado e assista a palestra do 3º Fórum BISTEC sobre o produto.</div>

    THanks in advance.

    https://ww.wp.xz.cn/plugins/insert-php/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Rodrigo Gomes,

    The PHP code between the [insert_php] and [/insert_php] tags must be complete in itself. There is no outside scope.

    This page is handy for reference about that and other limitations you may encounter:

    http://www.willmaster.com/software/WPplugins/insert-php-wordpress-plugin-instructions.php

    Perhaps a solution to the issue you presented is to let the PHP code echo the code for the CSS style. Something like this:

    [insert_php]
    $time = date("H");
    if( $time >= 17 && $time < 19 )
       $img_name = 'http://www.bistec.com.br/novo/wp-content/uploads/2014/11/Sweda-Apas-g-2010-shop_166110151912930.jpg';
    else( $time >= 19 && $time < 6 )
       $img_name = 'http://www.bistec.com.br/novo/wp-content/uploads/2014/11/padarias560.jpg';
    echo "<style>.my-class{background-image:url('$img_name');}</style>";
    [/insert_php]
    
    <div class="my-class">Aproveite que o S@T Sweda - Soluções em Automação Comercial foi homologado e assista a palestra do 3º Fórum BISTEC sobre o produto.</div>

    Will

    Gratuitous post to mark topic resolved.

    Thread Starter Rodrigo Gomes

    (@konoma)

    Sorry to delay answering the message. I still couldn’t test the method, but I thank you for the quick answer, and for the link. If I need more information, I’ll get in touch. Thanks again!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘T_VARIABLE error’ is closed to new replies.