Jacorre
  • Services
  • Projects
  • Tutorials
  • Blog
  • Contact Us
Jacorre on Facebook Jacorre on Twitter Jacorre RSS Feed

The WordPress Loop

The WordPress Loop

Tutorial Category: WordPress

Share This:

Share on Facebook Share on Twitter Share by Email

One of the most important things to learn when it comes to WordPress is “the loop”. It’s the heart of the system. Let’s take a look at the infamous loop!

1
2
3
4
5
6
7
8
9
10
11
12
13
<!--?php if (have_posts()) : ?-->
 
<!--?php while (have_posts()) : the_post(); ?-->
 
// Loop information to display posts goes here...
 
<!--?php endwhile; ?-->
 
<!--?php else: ?-->
 
// If no posts found, what should I display?
 
<!--?php endif; ?-->

<!--?php if (have_posts()) : ?--> <!--?php while (have_posts()) : the_post(); ?--> // Loop information to display posts goes here... <!--?php endwhile; ?--> <!--?php else: ?--> // If no posts found, what should I display? <!--?php endif; ?-->

Above is the basic loop structure. Let’s break it down in plain English.

  1. Are there any posts?
  2. If yes, continue to display them until there aren’t any left.
  3. If no, display something letting the visitor know there are no posts available.

Where do I find the loop?

The loop can be found on theme template files like archive.php, index.php, and search.php.

What does the loop look like with actual template tags?

Now that we have a general understanding of how the loop works, let’s show an example of how to display information within the loop.

1
2
3
<!--?php if (have_posts()) : ?-->
 
<!--?php while (have_posts()) : the_post(); ?-->

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

 

| | |

Nothing Found

Sorry, there are no posts.

There may be some things you might not recognize above if you’re not familiar with WordPress Template Tags. You should definitely read up on them when trying to understand how WordPress functions.

There are so many ways the loop can be used. It’s really up to you and how you want to style the content. Have fun with it, the possibilities are endless!

Share This:

Share on Facebook Share on Twitter Share by Email

Related Tutorials


Custom WordPress Admin Logo

Count And Display Number Of WordPress Posts

Count And Display Number Of WordPress Posts

WordPress Shortcode To List Subpages

WordPress Shortcode To List Subpages

Search

Categories

  • Corel Draw
  • CSS
  • Flash
  • Google Apps Script
  • Illustrator
  • Photoshop
  • PHP
  • WordPress

Buy Now

the_title()
Gift Boxes with Ribbon

the_title()
Attorney/Law Firm

the_title()
Country Flags

View All

Copyright © 2023 Jacorre, All Rights Reserved.
  • Links
  • Terms
  • Privacy Policy

Log in