解析错误:语法错误、函数中意外'<'.php



我知道这是一个常见的错误,但我不确定我的代码出了什么问题。我得到错误解析错误:语法错误,意外的'<'在/home/content/56/11192256/html/wp-content/themes/aggregate/functions.php第382行

任何帮助都将非常感激!

function et_delete_featured_ids_cache(){ 
    if ( false !==get_transient( 'et_featured_post_ids' ) )
        delete_transient('et_featured_post_ids' );
    }
}
if ( ! function_exists( 'et_list_pings' ) ){ 
    function et_list_pings($comment, $args, $depth) { 
        $GLOBALS['comment'] = $comment; ?> 
            <li id="comment-<?php comment_ID(); ?>">
            <?php comment_author_link(); ?> - <?php comment_excerpt(); ?> <?php ?>
    }
} 
?>       
<style type="text/css"> body { color: #<?php echo
esc_html(get_option($shortname.'_color_mainfont')); ?>; }
    #    content-area a { color: #<?php echo
    #esc_html(get_option($shortname.'_color_mainlink')); ?>; }
        ul.nav li a { color: #<?php echo
    esc_html(get_option($shortname.'_color_pagelink')); ?>
    !important; } ul.nav > li.current_page_item > a, ul#top-menu
    > li:hover > a, ul.nav > li.current-cat > a { color: #<?php
    echo
    esc_html(get_option($shortname.'_color_pagelink_active'));
    ?>; } h1, h2, h3, h4, h5, h6, h1 a, h2 a, h3 a, h4 a, h5 a,
    h6 a { color: #<?php echo
    esc_html(get_option($shortname.'_color_headings')); ?>; }
    #    sidebar a { color:#<?php echo
    #esc_html(get_option($shortname.'_color_sidebar_links')); ?>;
    #}
        .footer-widget { color:#<?php echo
    esc_html(get_option($shortname.'_footer_text')); ?> }
    #    footer a, ul#bottom-menu li a { color:#<?php echo
    #esc_html(get_option($shortname.'_color_footerlinks')); ?> }
    </style>
<?php }

看起来你缺少一个{

function et_delete_featured_ids_cache(){ 
    if ( false !==get_transient( 'et_featured_post_ids' ) ) {
    //                                                      ^ Here
        delete_transient('et_featured_post_ids' );
    }
}

问题是

//HERE-------------------------------------------------V
if ( false !==get_transient( 'et_featured_post_ids' ) ){
    delete_transient('et_featured_post_ids' );
}

定义if的代码块缺少左花括号。

为了避免这些问题,请使用php语法感知编辑器。我通过简单地将代码粘贴到IDE中并查看它显示错误的位置来发现此错误。

这里有一个免费的列表

除了前面提到的缺少括号之外,这也不会起作用并导致解析错误:

#    sidebar a { color:#<?php echo
#esc_html(get_option($shortname.'_color_sidebar_links')); ?>;
#}

您可能已经注释掉了一些行,但是php会运行并报错。

相关内容

最新更新