在添加“;get_the_except";到single.php


unexpected T_String when adding "get_the_excerpt" to single.php

当我添加时

<?php $excerpt = get_the_excerpt() ?>

对于下面的单页php代码,我得到了"解析错误:语法错误,第10行出现意外的T_STRING"

<?php get_header(); ?>
<div class="post"><?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div <?php post_class('margin') ?> id="post-<?php the_ID(); ?>">
<div class="casestudy"><a class="anchor-hover">
<?php echo get_the_post_thumbnail( $post->ID ); ?>
    <span class="details">
        <p class="desc"><?php $excerpt = get_the_excerpt() ?>
</p>
</span>
</a>
<?php the_content(); ?>
        </div>
<?php endwhile; endif; ?>
</div>
<?php get_footer(); ?>

我的functions.php文件最初没有

add_filter( 'get_the_excerpt', 'wp_trim_excerpt');

所以我添加了它,但我仍然得到了错误。我在这里错过了什么?我把它从循环中取出来了吗?

我相信你最后忘记了;

我也很好奇,为什么你只是在<p>中设置变量,而不是在echo中设置它?

您需要一个分号:)简单的错误是最糟糕的,对吗?