你好,有人可以帮我吗,我的PHP成功编译时遇到了问题,它说这是最后一行,但我认为最后一行是对的 没有足够的经验知道它是否正确
<?php get_header(); ?>
<?php if( have_posts() ) { ?>
<?php while( have_posts() ) { ?>
<?php the_post(); ?>
<h2>
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title() ?> </a>
</h2>
} else { ?>
<p>Sorry, No post matched</p>
<?php } ?>
<?php get_footer(); ?>
首先,您还没有关闭while循环。 并且没有打开的 php。 你不能做</h2> } else { ?>
<?php get_header(); ?>
<?php if(have_posts()) { ?>
<?php while(have_posts()) { ?>
<?php the_post(); ?>
<h2>
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title() ?> </a>
</h2>
<?php } //while end
} else { ?>
<p>Sorry, No post matched</p>
<?php } ?>
<?php get_footer(); ?>
试试这段代码。
<?php get_header(); ?>
<?php if( have_posts() ) { ?>
<?php while( have_posts() ) : the_post(); ?>
<h2>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title() ?></a>
</h2>
<?php endwhile; ?>
<?php } else { ?>
<p>Sorry, No post matched</p>
<?php } ?>
<?php get_footer(); ?>
您尚未关闭while循环。试试这个:
<?php get_header(); ?>
<?php if(have_posts()) { ?>
<?php while(have_posts()) { ?>
<?php the_post(); ?>
<h2>
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title() ?> </a>
</h2>
<?php } // end while loop (here was you mistake) ?>
<?php } else { ?>
<p>Sorry, No post matched</p>
<?php } ?>
<?php get_footer(); ?>