Functions/loop collections

loop_collections() loops through an array of collections, enabling a theme writer to display metadata for each collection in the loop.

Usage

<?php loop_collections(); ?>

Arguments

None

Examples

Default code on collections/browse.php

The following example can be used on the collections/browse.php page in the default theme. An array of collections is already available for that view, so this example simply loops through that array of collections, and displays the title of each collection with a link.

<?php while (loop_collections()): ?>
 
    <h3><?php echo link_to_collection(collection('Title'), array('class'=>'permalink')); ?></h3>
 
<?php endwhile; ?>

Looping Items Elsewhere

If you wish to loop through collections in template files other than collections/browse.php, you'll need to use the set_collections_for_loop helper to set an array of collections first. The following example is on the index.php file of the default theme. The loop_collections helper uses the array of collections created in the set_collections_for_loop helper:

<?php set_collections_for_loop(recent_collections(5)); ?>
<?php if (has_collections_for_loop()): ?>
    <ul class="collections-list">
    <?php while (loop_collections()): ?>
        <li class="collection">
    	    <h3><?php echo link_to_collection(); ?></h3>
            <?php if($desc = collection('Description', array('snippet'=>150))): ?>
            <div class="collection-description"><?php echo $desc; ?></div>
            <?php endif; ?>		
    	</li>		
    <?php endwhile; ?>
    </ul>
<?php else: ?>
    <p>No recent collections available.</p>
<?php endif; ?>