错误:添加


ERROR : adding <div> container to function.php

容器函数。php。

我得到以下错误:

解析错误:语法错误,意想不到的'<'在/home/u7mtb69/public_html/wpsitehrhhw/wp-content/themes/hrhhw.1.1/functions.php第1201行

我试图在我的function.php文件中添加元框到自定义post节。

文件工作得很好,直到我添加<div>容器,然后我得到一个错误-但容器看起来是正确的。

谁能告诉我是什么问题?
// Add WHEELS meta boxes
    add_action( 'add_meta_boxes' , 'wheel_meta_boxes' );
    function wheel_meta_boxes() {
        add_meta_box(
        'wheel_info',
        __( 'Wheel Info'),
        'wheel_info_div',
        'wheels'
        );
    }
    function wheel_info_div( $post ) {
      // Use nonce for verification
      wp_nonce_field( plugin_basename( __FILE__ ), 'wheel_noncename' );
    }
// WHEELS fields for data entry
<div>
    <label for="tire_code">
        <?php _e("Tire Code");?>
    </label>
        <input type="text" name="tire_code" value="<?php echo get_post_meta($post->ID, 'tire_code', true);?>" />
        <br>
    <label for="tire_name">
        <?php _e("Tire Name");?>
    </label>
        <input type="text" name="tire_name" value="<?php echo get_post_meta($post->ID, 'tire_name', true);?>" />
        <br>
    <label for="tire_bname">
        <?php _e("Tire Brand");?>
    </label>
        <input type="text" name="tire_bname" value="<?php echo get_post_meta($post->ID, 'tire_bname', true);?>" />
        <br>
    <input type="button" value="Create" id="create" />
    <input type="button" value="Replace" id="replace" />
    </div>
// NEXT
// END
?>

问题是您将HTML放在PHP块中。别那样做。

你必须记住PHP和HTML是完全不同的。除了浏览器看到的HTML是运行PHP脚本的PHP解释器的结果(其中可能包括一些硬编码的HTML以保留在输出中,如<div>)之外,没有任何关系。所以当你看到一个PHP错误时,它不会是HTML的错误。


错误:

<?php
$somePHPCodeHere = 3;
<p>Some HTML here.</p>
?>

:

<?php
$somePHPCodeHere = 3;
?>
<p>Some HTML here.</p>

换句话说:您只需要在这行后面添加结束php标记?>:

// WHEELS fields for data entry
?>