2015-04-16 16 views
0

我下面這個教程自定義文章類型: http://www.elegantthemes.com/blog/tips-tricks/creating-custom-post-types-in-wordpress自定義後類型在語法錯誤意外ENDIF WP結果

我使用下劃線啓動WP主題。 http://underscores.me/

我創建的代碼波紋管, 一個頁面電影reviews.php文件,但我得到的頁面上的語法錯誤: 解析錯誤:語法錯誤,意外「ENDIF」(T_ENDIF)在C:\ WAMP \ WWW \ WordPress的\可溼性粉劑內容\主題\在線原型\頁面電影reviews.php 34

我的代碼:

<?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(); ?> 
+0

您正在使用「花括號」語法「If(something){// code}」,它不需要'endif;'語句 –

回答

0

通常使用WP循環時, 你需要有條件c嘿,如果有帖子符合你的標準。 我相信你從其他地方複製它,但忘記複製循環前的條件。您只需從以下代碼中刪除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(); 
?>