0

我收到此错误Parse error: syntax error, unexpected T_DEFAULT in ../../functions.php on line 22

这是第 22 行周围的 functions.php 部分(“默认”特别是第 22 行):

<?php
        break;
    default :
?>

它是来自 Wordpress 的 TwentyEleven functions.php 的默认代码,不幸的是,我仍在大量学习 PHP,所以我完全不确定为什么会发生错误。有任何想法吗?

ETA 这里是完整的functions.php

if ( ! function_exists( 'twentyeleven_comment' ) ) :
/**
 * Template for comments and pingbacks.
 *
 * To override this walker in a child theme without modifying the comments template
 * simply create your own twentyeleven_comment(), and that function will be used instead.
 *
 * Used as a callback by wp_list_comments() for displaying the comments.
 *
 * @since Twenty Eleven 1.0
 */
function twentyeleven_comment( $comment, $args, $depth ) {
    $GLOBALS['comment'] = $comment;
    switch ( $comment->comment_type ) :
        case 'pingback' :
        case 'trackback' :
    ?>
    <li class="post pingback">
        <p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p>
    <?php
            break;
        default :
    ?>
    <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
        <article id="comment-<?php comment_ID(); ?>" class="comment">
            <footer class="comment-meta">
                <div class="comment-author vcard">
                    <?php
                        $avatar_size = 68;
                        if ( '0' != $comment->comment_parent )
                            $avatar_size = 39;

                        echo get_avatar( $comment, $avatar_size );

                        /* translators: 1: comment author, 2: date and time */
                        printf( __( '%1$s on %2$s <span class="says">said:</span>', 'twentyeleven' ),
                            sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
                            sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
                                esc_url( get_comment_link( $comment->comment_ID ) ),
                                get_comment_time( 'c' ),
                                /* translators: 1: date, 2: time */
                                sprintf( __( '%1$s at %2$s', 'twentyeleven' ), get_comment_date(), get_comment_time() )
                            )
                        );
                    ?>

                    <?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?>
                </div><!-- .comment-author .vcard -->

                <?php if ( $comment->comment_approved == '0' ) : ?>
                    <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyeleven' ); ?></em>
                    <br />
                <?php endif; ?>

            </footer>

            <div class="comment-content"><?php comment_text(); ?></div>

            <div class="reply">
                <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>&darr;</span>', 'twentyeleven' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
            </div><!-- .reply -->
        </article><!-- #comment-## -->

    <?php
            break;
    endswitch;
}
endif; // ends check for twentyeleven_comment()
4

4 回答 4

4

我用下面的代码遇到了这个问题。注意:使用“case default”,这是不正确的

switch($vars) {
  case "0":
    print '1 comment';
    break;
  case default:
    print "$vars comments";  
}

代码应如下(仅默认)

switch($vars) {
  case "0":
    print '1 comment';
    break;
  default:
    print "$vars comments";

}
于 2014-04-03T02:33:47.473 回答
0

尝试删除default:. 并确保这行代码里面

switch(){

}
于 2012-10-16T18:03:11.390 回答
0

这似乎是 switch 语句的一部分,通常采用以下结构:

switch($aaa) {
    case 1:
        //do something
        break;
    case 2:
        //do something else
        break;
    case 3:
        ...
        ...
        ...
    default:
        /do something else again
        break;
 }

您可以在此处获取所需的所有信息http://php.net/manual/en/control-structures.switch.php

于 2012-10-16T18:06:12.547 回答
0

我在复制/粘贴代码时疏忽了;忘记打开<?php和关闭?>

于 2012-10-16T18:10:04.983 回答