首页 > 解决方案 > 这个循环在服务器上不能正常工作?

问题描述

我已将此代码添加到 Wordpress 主题的 front-page.php 中,并为相关帖子添加了特色图片,但结果是以下错误消息: Parse error: syntax error, unexpected end of file in C:\xampp\ htdocs\wordpress\wp-content\themes\Resto 2\front-page.php on line 89 您的网站出现严重错误。这是我要使用的循环

<section id="features">
        <ul>
            <?php /*start the loop*/ ?>
            <?php $myquery = new WP_Query('category_name=menu-items&posts_per_page=4'); ?>
           <!--<?php while ( $myquery->have_posts() ) :  $myquery->the_post(); ?>-->
            <li>
                <?php the_post_thumbnail(); ?>
                <a href="<?php the_permalink() ?> "><?php the_title(); ?><a/>
                <span><?php echo get_post_meta($post->ID, 'price', true); ?></span>
                <span class="star-<?php echo get_post_meta($post->ID, 'rating', true); ?>rating"></span>
            </li>
        </ul>
     </section>

标签: phphtmlwordpressloopswordpress-theming

解决方案


添加endwhile;到您的代码中。

<!--<?php while ( $myquery->have_posts() ) :  $myquery->the_post(); endwhile; ?>-->

或做不同类型的while:

<!--<?php while ( $myquery->have_posts() ){  $myquery->the_post();} ?>-->

推荐阅读