WordPress Words: The Loop

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.
WordPress Codex: The Loop

The loop will start with code that checks to see if the current page is supposed to display a listing of several posts or just one post. If a page is supposed to list blog posts, then it will list out a title and excerpt for each post. If the page contains only a single page or a single post, then the loop will display the content for that page.

Here are some examples of The Loop in code that you would use in index.php.

This is where it starts:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

This is where it ends:

<?php endwhile; else : ?>
	<p>
<?php _e( 'Sorry, no posts matched your criteria.' ); ?>
</p>
<?php endif; ?>

Here is a video tutorial explaining the things you can do with using Loop:

References

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s