WordPress Plugin for Custom Loops: Lyza Loop

A WordPress Plugin for theme developers and hackers who spend a lot of time dealing with custom loops.

Overview

Lyza Loop is a WordPress plugin that aims to:

  • Dramatically shorten the time required to code custom loops
  • Modularize custom loop markup using what I hope is a straightforward templating process
  • Provide convenient batching variables

How it Works

There are two parts to the lyza_loop() function:

  1. Finding posts (or pages): extending query_posts() — lyza_loop() takes any argument WordPress’ own query_posts() takes
  2. Rendering relevant posts or pages: using “loop templates.” A loop template is a PHP file with markup (and logic) you’d like to use for each post/page in the loop.

Examples

Example 1

The unordered list above was created by using the following code:

<?php
    $args = Array('showposts' => 4,
                  'template' => 'simple_UL');
    lyza_loop($args);
?>
Example 2

This list was created with this code (the category with ID 3 is my “Books” category):

<?php
    $args = Array('showposts'   => 3,
                  'template'    => 'simple_UL',
                  'cat'         => 3);
    lyza_loop($args);
?>

Although the last post in the first list (“This Sceptered Isle”) is in my “Books” category, I have Lyza Loop configured not to repeat posts.

These two examples both use the ’simple_UL’ loop template (which is a default template I bundle in with the plugin). This template is a PHP file that looks like this:

<?php if($loop_first): ?>
    <ul>
<?php endif; ?>
    <li id="post_link_<?php the_ID(); ?>" <?php post_class(); ?>>
        <?php the_time('M j'); ?>
        <a href="<?php the_permalink(); ?>" title="Read <?php the_title(); ?>">
        <?php the_title(); ?>
        </a>
    </li>
<?php if($loop_last): ?>
    </ul>
<?php endif; ?>
Wonderful games with Caslon