这段代码出了什么问题? (意外的$ end在最后一行)

时间:2011-02-18 23:33:09

标签: php

<?php
/*
Template Name: Videos
*/
?>

<?php get_header();?>

    <section id="content">
        <section id="main">
            <?php 
                $c=0;
                $i=1;

                $temp = $wp_query;
                $wp_query = null;
                $wp_query = new WP_Query();
                $wp_query->query('post_type=videos' . '&paged=' . $paged . '&posts_per_page=16');

                while ( $wp_query->have_posts() ) : $wp_query->the_post(); $c++;
            ?>

            <?php if (have_posts()) : ?>

                <?php while (have_posts()) : the_post(); $c++; ?>
                    <article class="post<?php if($i%4 == 0) { echo ' right'; }; $i++; ?>" id="post-<?php the_ID(); ?>">
                        <section class="entry">
                            <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'video-thumb' ); } ?></a>
                        </section>
                        <section class="description">
                            <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                        </section>
                    </article>

                <?php
                    endwhile; 
                    wp_pagenavi();
                    $wp_query = null;
                    $wp_query = $temp;
                    wp_reset_query();
                ?>

                <?php if( $c < 16 ) : for ($dummy= $c; $dummy < 16; $dummy++) : ?>

                    <article class="post<?php if($i%4 == 0) { echo ' right'; }; $i++; ?>" id="post-<?php the_ID(); ?>">
                        <img src="<?php bloginfo('template_url'); ?>/images/dummy-video.gif" alt="Post coming soon!" />
                    </article>

                    <?php endfor;?>

                <?php endif;?>

            <?php endif; ?>

            <section id="map">
                <img src="<?php bloginfo('template_url') ?>/images/interactive-map.jpg" alt="Interactive Map" />
            </section>
        </section>

<?php get_sidebar(); ?>

    </section>

<?php get_footer(); ?>

以下是pastebin版本:http://pastebin.com/2Grja48U

3 个答案:

答案 0 :(得分:4)

我认为您在第一个endwhile;声明中缺少while

答案 1 :(得分:2)

<?php while ( ... ) : ?>

    <section id="map">
        <img src="<?php bloginfo('template_url') ?>/images/interactive-map.jpg" alt="Interactive Map" />
    </section>

<?php endwhile; ?>

这将为你解决

答案 2 :(得分:1)

正如消息所说的那样:解析器在没有预期的时候到达文件的末尾(某些东西,可能是while,尚未关闭)。