Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php wp中的自定义post类型导致语法错误意外endif_Php_Wordpress - Fatal编程技术网

Php wp中的自定义post类型导致语法错误意外endif

Php wp中的自定义post类型导致语法错误意外endif,php,wordpress,Php,Wordpress,以下是有关自定义帖子类型的教程: 我正在使用下划线主题。 我用下面的代码创建了一个page-movie-reviews.php文件, 但是我在页面上看到一个语法错误: 分析错误:语法错误,在第34行的C:\wamp\www\wordpress\wp content\themes\prototype\page-movie-reviews.php中出现意外的“endif”(T\u endif) 我的代码: <?php /** * Template Name: Movie Reviews

以下是有关自定义帖子类型的教程:

我正在使用下划线主题。

我用下面的代码创建了一个page-movie-reviews.php文件, 但是我在页面上看到一个语法错误: 分析错误:语法错误,在第34行的C:\wamp\www\wordpress\wp content\themes\prototype\page-movie-reviews.php中出现意外的“endif”(T\u endif)

我的代码:

<?php
/**
 * Template Name: Movie Reviews
 * @package prototype
 */

get_header(); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">




    <div class="entry-content">
     <?php
        if ( has_post_thumbnail() ) {
          the_post_thumbnail();
        }
          the_content();
        ?>
    </div>



    <?php $query = new WP_Query( array('post_type' => 'movie-reviews', 'posts_per_page' => 5 ) );
     while ( $query->have_posts() ) : $query->the_post(); ?>
    <?php endif; wp_reset_postdata(); ?>
    <?php endwhile; ?>





            <?php while ( have_posts() ) : the_post(); ?>

                <?php get_template_part( 'content', 'page' ); ?>

                <?php
                    // If comments are open or we have at least one comment, load up the comment template
                    if ( comments_open() || get_comments_number() ) :
                        comments_template();
                    endif;
                ?>

            <?php endwhile; // end of the loop. ?>








        </main><!-- #main -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

通常在WP中使用循环时, 你需要有一个条件来检查是否有符合你标准的帖子。 我相信您是从其他地方复制的,但是忘记复制循环之前的条件。您只需删除
endif从以下代码在循环之前添加
if($query->have_posts()):
条件

提示:确保在需要时在代码中使用缩进和换行。 这样就更容易找到问题所在

<?php
$query = new WP_Query( array('post_type' => 'movie-reviews', 'posts_per_page' => 5 ) );
while ( $query->have_posts() ) : $query->the_post(); ?>
<?php 
endif; //<-- you can remove this one.
wp_reset_postdata();
?> 

您使用的是“花括号”语法
If(something){//code}
它不需要
endif语句