抱歉,我是一个PHp初学者,我不知道为什么这个循环对我的标签不起作用。php页面欢迎任何帮助。
<?php get_header(); ?>
<div class="posts"><!-- BLOG -->
<!-- Shapes on sides -->
<div class="shapes_left"> </div>
<div class="shapes_right"> </div>
<?php if (is_tag()) { ?>
<div id="archive_title">
<h1><?php single_tag_title(); ?></h1>
<?php }?>
</div>
<div id="featured_home">
<?php $counter = 0;
while ( have_posts() ) {
$counter += 1;
if ( $counter > 5 ) {
break;
}
the_post();
?>
<article class="sticky">
<div class="desc">
<div class="desc_over"><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2></div>
<?php the_post_thumbnail(large); ?>
</div>
</article>
<?php }?>
</div>
<?php while( have_posts() ) {
the_post();
// it\'s a post! Display the post!
} ?>
<div class="post_main">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<ul class="postinfo">
<li>Posted by <?php the_author_link(); ?></li>
<li><?php the_time( \'jS F Y\'); ?></li>
</ul>
<?php the_content( \'\'); ?>
<div class="read_more_blog"><a href="<?php the_permalink(); ?>">Read More</a></div>
</div>
<?php endwhile; ?>
<nav id="pagination"> <!-- PAGINATION FOR BLOG -->
<ul>
<li class="older"><?php next_posts_link( \'Older posts\'); ?></li>
<li class="newer"><?php previous_posts_link( \'Newer posts\'); ?></li>
</ul>
</nav>
</div>
<!-- END OF BLOG PAGINATION -->
<?php else : ?>
<div id="post">
<!-- 404 Messege -->
<h3>404 ERROR!!</h3>
<p>Sorry we can\'t seem able to find what you are looking for</p>
<p><a href="<?php echo home_url(); ?>">Click here to get back to the homepage</a>
</p>
</div>
<?php endif; ?>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
最合适的回答,由SO网友:erichmond 整理而成
您应该进一步清理它,但这将修复您的代码:
<?php get_header(); ?>
<div class="posts"><!-- BLOG -->
<!-- Shapes on sides -->
<div class="shapes_left"> </div>
<div class="shapes_right"> </div>
<?php if (is_tag()) { ?>
<div id="archive_title">
<h1><?php single_tag_title(); ?></h1>
<?php }?>
</div>
<div id="featured_home">
<?php $counter = 0;
while ( have_posts() ) {
$counter += 1;
if ( $counter > 5 ) {
break;
}
the_post();
?>
<article class="sticky">
<div class="desc">
<div class="desc_over"><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2></div>
<?php the_post_thumbnail(large); ?>
</div>
</article>
<?php }?>
</div>
<?php
// I\'ve added the missing if statement and corrected some php grammar
if ( have_posts() ) : while( have_posts() ) :
the_post();
// it\'s a post! Display the post!
?>
<div class="post_main">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<ul class="postinfo">
<li>Posted by <?php the_author_link(); ?></li>
<li><?php the_time( \'jS F Y\'); ?></li>
</ul>
<?php the_content( \'\'); ?>
<div class="read_more_blog"><a href="<?php the_permalink(); ?>">Read More</a></div>
</div>
<?php endwhile; ?>
<nav id="pagination"> <!-- PAGINATION FOR BLOG -->
<ul>
<li class="older"><?php next_posts_link( \'Older posts\'); ?></li>
<li class="newer"><?php previous_posts_link( \'Newer posts\'); ?></li>
</ul>
</nav>
</div>
<!-- END OF BLOG PAGINATION -->
<!-- because the if statement has been started the else will now work -->
<?php else : ?>
<div id="post">
<!-- 404 Messege -->
<h3>404 ERROR!!</h3>
<p>Sorry we can\'t seem able to find what you are looking for</p>
<p><a href="<?php echo home_url(); ?>">Click here to get back to the homepage</a>
</p>
</div>
<!-- now the if statement is ended -->
<?php endif; ?>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
希望这有帮助