doupafu6980 2015-04-16 11:35
浏览 22
已采纳

wp中的自定义帖子类型导致语法错误意外endif [重复]

This question already has an answer here:

I'm following this tutorial for custom post types: http://www.elegantthemes.com/blog/tips-tricks/creating-custom-post-types-in-wordpress

I'm using underscore starter wp theme. http://underscores.me/

I've created a page-movie-reviews.php file with the code bellow, but I get a syntax error on the page: Parse error: syntax error, unexpected 'endif' (T_ENDIF) in C:\wamp\www\wordpress\wp-content\themes\prototype\page-movie-reviews.php on line 34

my code:

<?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(); ?>
</div>
  • 写回答

1条回答 默认 最新

  • doubeng9407 2015-04-16 11:42
    关注

    Usually when using a loop in WP, you need to have a condition to check if there are posts that fits your criteria. I believe you copied it from somewhere else but forgot to copy the condition that comes before the loop. All you need to do is to remove the endif; from the following code or add a if($query->have_posts()): condition before the loop.

    Tip: Make sure to use indents and break-lines in your code when needed. That way it would be much easier to locate the problem.

    <?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();
    ?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路