如何修复这个PHP语法错误?

时间:2014-03-10 09:48:12

标签: php html5 wordpress

如何修复第4行的语法错误。

    if ( function_exists('register_sidebar') )
    register_sidebar(array(
        'before_widget' => '',
        'after_widget' => '<img src="<?php bloginfo('template_url');?> /img/sub_page/horizontal_separator.png" style="margin-bottom: 15px;" alt="" />',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));

add_action( 'init', 'register_my_menu' );

3 个答案:

答案 0 :(得分:1)

您需要连接字符串。您正试图在PHP中包含PHP标记。这将导致输出标记,但不会解释它们。您可以使用.

的字符串连接字符
'after_widget' => '<img src="'.bloginfo('template_url').'/img/sub_page/horizontal_separator.png" style="margin-bottom: 15px;" alt="" />',

作为参考,将来如果您需要在由单引号括起的字符串中包含单引号,或在双引号括起的字符串中包含双引号,则可以使用\'和{{1}来转义它们}} 分别。例如:

\"

答案 1 :(得分:1)

你在字符串中有一个phpblock

更改

    'after_widget' => '<img src="<?php bloginfo('template_url');?> /img/sub_page/horizontal_separator.png" style="margin-bottom: 15px;" alt="" />',

    'after_widget' => '<img src="' . bloginfo('template_url') . '/img/sub_page/horizontal_separator.png" style="margin-bottom: 15px;" alt="" />',

答案 2 :(得分:1)

您不需要重新打开php,因为您已经在回显字符串。

应该是:

if ( function_exists('register_sidebar') )
    register_sidebar(array(
        'before_widget' => '',
        'after_widget' => '<img src="'.bloginfo('template_url').'"/img/sub_page/horizontal_separator.png" style="margin-bottom: 15px;" alt="" />',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));

add_action( 'init', 'register_my_menu' );
相关问题