The Loop is PHP code used by WordPress to display posts. Using The Loop, WordPress processes each post to be displayed on the current page, and formats it according to how it matches specified criteria within The Loop tags. Any HTML or PHP code in the Loop will be processed on each post.
When WordPress documentation says "This tag must be within The Loop", such as for specific Template Tags or plugins, the tag will be repeated for each post. For example, The Loop displays the following information by default for each post:
- Title (the_title())
- Time (the_time())
- Categories (the_category()).
The loop starts here:
<?php if ( have_posts() ) : while (
have_posts() ) : the_post(); ?>
and ends here:
<?php endwhile; else : ?>
<p><?php
_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
This is using PHP's alternative syntax for control
structures, and could also be expressed as:
<?php
if ( have_posts() ) {
while
( have_posts() ) {
the_post();
//
//
Post Content here
//
}
// end while
} // end if
?>
No comments:
Post a Comment