【发布时间】:2015-01-22 19:21:56
【问题描述】:
我正在排除“解析错误:语法错误,意外的 'else'”,我认为问题与我的括号有关。我是 php 新手,所以我不太清楚这里出了什么问题。这是一个 wordpress 页面模板,它将检查用户是否已登录...如果没有,它将显示一条消息,说明您需要登录才能查看该页面。这是产生问题的 .php 模板的代码:
<?php
/*
Template Name: Logged-In Users Page
*/
?>
<!--?php if(is_user_logged_in()):?-->
<?php get_header(); ?>
<?php
$sidebar_position = get_post_meta( get_queried_object_id(), 'vw_page_sidebar_position', true );
$sidebar_position_class = '';
if ( 'left' == $sidebar_position ) {
$sidebar_position_class = 'sidebar-left';
} else if( 'right' == $sidebar_position ) {
$sidebar_position_class = 'sidebar-right';
} else {
$sidebar_position_class = 'sidebar-hidden';
}
?>
<div id="page-wrapper" class="container <?php echo $sidebar_position_class; ?>">
<div class="row">
<div id="page-content" class="col-sm-7 col-md-8">
<?php if (have_posts()) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'templates/page-title' ); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'clearfix' ); ?>>
<?php get_template_part( 'templates/post-formats/format', get_post_format() ); ?>
<div class="post-content"><?php the_content(); ?></div>
</article>
<?php endwhile; ?>
<?php get_template_part( 'templates/pagination' ); ?>
<?php comments_template(); ?>
<?php else : ?>
<h2><?php _e('Not Found', 'envirra') ?></h2>
<?php endif; ?>
</div>
<?php if ( 'left' == $sidebar_position || 'right' == $sidebar_position ) : ?>
<aside id="page-sidebar" class="sidebar-wrapper col-sm-5 col-md-4">
<?php get_sidebar(); ?>
</aside>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
<?php else:
wp_die('Sorry, you must first <a href="/wp-login.php">log in</a> to view this page. You can <a href="/wp-login.php?action=register">register free here</a>.');
endif; ?>
【问题讨论】:
-
第几行?错误应该说
-
<?php else : ?>缺少其开头等效项。<?php if (condtion):?>- 如果不使用,请将其删除。 -
而不是
<?php else: wp_die...
标签: php parsing syntax brackets