2012-05-17 122 views
0

這是我第一次搞亂Wordpress模板和我第一次使用PHP(除了偶爾的服務器包括)。也就是說,我對PHP一無所知,只能掌握語法。

我想創建一些自定義的循環,一旦我得到一個工作,我只需複製粘貼的工作代碼,更改了ID,並希望工作。傻或許?無論如何,我得到一個意外的$ 203行。

任何人願意告訴我是什麼原因造成的?提前致謝!

<!-- FEATURED LOOP --> 
<div class="featured"> 
<?php $my_query = new WP_Query('category_name=featured&showposts=1'); ?> 
<?php if (have_posts()) : ?> 
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> 

     <?php do_atomic('before_entry'); // origin_before_entry ?> 

     <div id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>"> 
      <?php do_atomic('open_entry'); // origin_open_entry ?> 

      <?php 
      if (current_theme_supports('get-the-image')) {        
       if (is_sticky ($post->ID)) { 
        get_the_image(array('meta_key' => 'Thumbnail', 'size' => 'single-thumbnail', 'image_class' => 'featured')); 
       } else { 
        get_the_image(array('meta_key' => 'Thumbnail', 'size' => 'thumbnail', 'image_class' => 'featured')); 
       } 
      } 
      ?> 

      <div class="sticky-header"> 
       <?php echo apply_atomic_shortcode('entry_title', '[entry-title]'); ?> 
       <?php echo apply_atomic_shortcode('byline', '<div class="byline">' . __('[entry-published] &middot; by [entry-author] &middot; in [entry-terms taxonomy="category" before=""] [entry-edit-link before=" &middot; "]', 'origin') . '</div>'); ?>     
      </div><!-- .sticky-header --> 

      <div class="entry-summary"> 
       <?php the_excerpt(); ?> 
       <?php wp_link_pages(array('before' => '<p class="page-links">' . __('Pages:', 'origin'), 'after' => '</p>')); ?> 
      </div><!-- .entry-summary --> 

      <?php do_atomic('close_entry'); // origin_close_entry ?> 
     </div><!-- .hentry --> 

     <?php do_atomic('after_entry'); // origin_after_entry ?> 

    <?php endwhile; ?> 
    <?php wp_reset_postdata(); // reset the query ?> 
<?php else : ?> 
<!--END FEATURED LOOP-->  

<!-- SUBFEATURED LOOP --> 
<div class="subfeatured"> 
<?php $my_query = new WP_Query('category_name=subfeatured&showposts=1'); ?> 
<?php if (have_posts()) : ?> 
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> 

     <?php do_atomic('before_entry'); // origin_before_entry ?> 

     <div id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>"> 
      <?php do_atomic('open_entry'); // origin_open_entry ?> 

      <?php 
       if (current_theme_supports('get-the-image')) { 
        if (is_sticky ($post->ID)) { 
         get_the_image(array('meta_key' => 'Thumbnail', 'size' => 'single-thumbnail', 'image_class' => 'featured')); 
        } else { 
         get_the_image(array('meta_key' => 'Thumbnail', 'size' => 'thumbnail', 'image_class' => 'featured')); 
        } 
       } 
      ?> 

      <div class="sticky-header"> 
       <?php echo apply_atomic_shortcode('entry_title', '[entry-title]'); ?> 
       <?php echo apply_atomic_shortcode('byline', '<div class="byline">' . __('[entry-published] &middot; by [entry-author] &middot; in [entry-terms taxonomy="category" before=""] [entry-edit-link before=" &middot; "]', 'origin') . '</div>'); ?> 
      </div><!-- .sticky-header --> 

      <div class="entry-summary"> 
       <?php the_excerpt(); ?> 
       <?php wp_link_pages(array('before' => '<p class="page-links">' . __('Pages:', 'origin'), 'after' => '</p>')); ?> 
      </div><!-- .entry-summary --> 

      <?php do_atomic('close_entry'); // origin_close_entry ?> 
     </div><!-- .hentry --> 

     <?php do_atomic('after_entry'); // origin_after_entry ?> 

    <?php endwhile; ?> 
    <?php wp_reset_postdata(); // reset the query ?> 
<?php else : ?>   
<!--END SUBFEATURED LOOP--> 
+0

通常,這個錯誤表明你錯過了循環的結束(for,foreach,while,if)。你可以檢查203行之前/之後看看是否是這種情況?要排除這一切,沒有行號,有點困難。 – tcole

+2

投票結束爲本地化。從[4,000多個其他問題]中可以很容易地知道這個錯誤的含義(http://stackoverflow.com/search?q=%5Bphp%5D+Unexpected+%24End+Error)。某處存在不匹配的控制結構。 –

+0

如果用'<?php endif;替換代碼中的兩個'<?php else:?>'行, 「你應該很好走。」 –

回答

3

的PHP代碼的最後一行必須是:

<?php else : ?> 

您需要完成該control structure。你錯過了這樣的東西:

<?php endif; ?> 
+1

找到了!對於這個問題的天真感到抱歉,Php會炒我的非開發人員的大腦。非常感謝! – user1398067