---
title: "Using The WordPress Loop"
description: "When developing WordPress themes, it's important to know about the loop. The WordPress Loop is a function that grabs posts from your database, and allows you to display multiple posts on a page, such..."
url: https://www.inmotionhosting.com/support/edu/wordpress/the-wordpress-loop/
date: 2014-07-08
modified: 2024-05-14
author: "Jeff Matson"
categories: ["WordPress Hosting", "WordPress Tutorials"]
type: post
lang: en
---

# Using The WordPress Loop

When developing WordPress themes, it’s important to know about the loop. The WordPress Loop is a function that grabs posts from your database, and allows you to display multiple posts on a page, such as the index page of a blog.

There are many advanced variations of the loop, but in this article we’ll focus on the basic loop, so you can build up from there.

If you would like more information on creating WordPress plugins, see our tutorial series on [creating your first WordPress plugin](https://www.inmotionhosting.com/support/edu/wordpress/plugins/create-a-wordpress-plugin/).

## What you will need…

In order to edit your theme, you will need a local development site, or you can edit the theme files on your server using the [cPanel File Manager](/support/edu/cpanel/using-file-manager-in-cpanel/). (It is recommended that you *do not* edit live site files for a production site.) Creating a local WordPress installation on your computer is outside the scope of this article.

You will also need a plain, bare bones text editor like Notepad, TextEdit, Sublime, or similar. Editing files in a Word document will add all kinds of extra text that will corrupt your file.

## How the Loop Works

So how does the loop work? A basic understanding of PHP is important here, but here are the basics.

- The loops checks for posts.
- If there are posts, each one will be displayed until there are no more.
- While displaying the posts, you can add any content or HTML.

The loop does its job best when you match the elements of your post (like the title, date, or other information) with an appropriate HTML tag.

## Starting the Loop

To begin the loop, simply initiate a PHP *while* statement, which will run as long as there are posts available to process:

```

```

## Inside the Loop

Within the loop, you would call functions like the_permalink(), the_title(), the_content(), and various other WordPress functions that you want displayed for each post on the page.

In this example, we just want to display the post title with a link to the main post, as well as the post content:

```

##
