WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Loop Templates

This page is marked as incomplete. You can help Codex by expanding it.

Introduction

Loop template files are used to format the loop based on what type of page you are visiting.

What Template File is Used?

You can have loop templates for different loops. For example: loop-archive.php or loop-category.php which represent different loops for archives and categories, respectively.

Examples

You can call a loop from inside one of your page templates like this:

<?php
 /* Run the loop to output the posts.
 * If you want to overload this in a child theme then include a file
 * called loop-index.php and that will be used instead.
 */
    get_template_part( 'loop', 'category' );
?>

Using this method will call the file loop-category.php and run the content within in it. Inside loop-category.php you might have code to format the loop just for category pages.

Further Reading

Related

Template Hierarchy: Category Templates, Tag Templates, Taxonomy Templates, Page Templates, Post Type Templates, Author Templates, Date Templates, Search Templates, 404 Templates, Attachment Templates, Loop Templates

See also index of Function Reference and index of Template Tags.