O'Reilly logo

WordPress Complete - Sixth Edition by Karol Król

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Main column – the loop

The most important part of the WordPress code comes next. It's called the loop, and it's an essential part of your theme. The loop's job is to display your posts in a 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required