【问题标题】:Unexpected T_ENDWHILE in loop.phploop.php 中的意外 T_ENDWHILE
【发布时间】:2013-12-31 15:15:37
【问题描述】:

我正在从头开始制作一个新主题(以前的主题已经好几年没有更新了),我想尝试一下。 一切似乎都很顺利,除了当我想列出帖子时,我收到了这个错误:

解析错误:语法错误,第 41 行 /wp-content/themes/pro/loop.php 中的意外 T_ENDWHILE

这是清理后的代码:

<?php if (have_posts()) : ?>
  <?php while (have_posts()) : the_post(); ?>
    <div class="panel panel-default">
    <div class="panel-heading">
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><small>, le <?php the_date(); ?></small></h2>
    </div>
    <div class="panel-body">
        <?php
            if ( $post->post_excerpt ){
                the_excerpt();?>
                <div class="btn-group">
                    <button type="button" class="btn btn-default"><a href="<?php the_permalink(); ?>">Lire la suite <i class="fa fa-arrow-right fa-fw"></i></a></button>
                </div>
            <?php }
            else {
                the_content();?>
    </div>
    <div class="panel-footer">
        <div class="btn-group">
            <button type="button" class="btn btn-default"><a href="<?php the_permalink(); ?>#comments"><i class="fa fa-comments fa-fw"></i> <?php get_comments_number(); ?></a></button>
        </div>
         
        <i class="fa fa-folder-open fa-fw"></i> Catégories : <?php the_category(', ') ?>
    </div>
    </div>
  <?php endwhile; ?>
<?php else : ?>
    <div class="jumbotron">
    <h1>Il n'y a rien à afficher.</h1>
    </div>
<?php endif; ?>

我将其用作 index/archive/tags.php :

<?php
get_header();
get_template_part('loop');
get_footer();
?>

我查看了以前的主题,我觉得它看起来不错。什么可能导致此错误?

【问题讨论】:

    标签: php wordpress-theming wordpress


    【解决方案1】:

    内部ifelse 分支(位于endwhile 之前的那个分支)在endwhile 关键字之前的某处缺少其}

    我猜代码应该是这样的:

    <div class="panel-body">
        <?php
            if ( $post->post_excerpt ){
                the_excerpt();?>
                <div class="btn-group">
                    <button type="button" class="btn btn-default"><a href="<?php the_permalink(); ?>">Lire la suite <i class="fa fa-arrow-right fa-fw"></i></a></button>
                </div>
            <?php }
            else {
                the_content();
            } /* <- This bracket is missing */ ?>
    </div>
    

    【讨论】:

    • 而且...你是对的,缺少括号导致错误。我不敢相信我忽略了它,即使我检查了多次。
    猜你喜欢
    • 2014-02-10
    • 1970-01-01
    • 2016-05-21
    • 1970-01-01
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多