Main column – the loop

This is the most important section of our WordPress code. It's called the loop, and it's an essential part of your new theme. The loop's job is to display your posts in reverse chronological order, choosing only those posts that are appropriate. You need to put all of your other post tags inside the loop. The basic loop text, which has to surround your post information, is displayed using the following code:

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
  <?php get_template_part('content', get_post_format()); ?>
<?php endwhile; else: ?>
  <?php get_template_part('content', 'none'); ?>
<?php endif; ?>

The get_template_part() function call that's right in the middle, fetches another file that contains ...

Get WordPress 5 Complete - Seventh Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.