# 1 : calling the_post without a loop will allow you to display only one message. This may be desirable on single-mail pages, for example, where the while often omitted:
<?php <p><?php the_content(); ?></p> <? else: ?> <p>No post found.</p> <? endif ?>
# 2 : you're right - the fragment you posted is redundant in the combination of if and while .
In most topics this usage is:
<?php if ( have_posts() ): while ( have_posts() ): the_post(); ?> <div class="post"><?php the_content(); ?></div> <?php endwhile; else: ?> <p>No posts found.</p> <?php endif; ?>
Using an if in this case allows you to display something if there are no messages at all. If we simply used the while in this code, pages without any messages would not produce anything.
source share