Functions/loop items

loop_items() loops through an array of items, enabling a theme writer to display metadata for each item in the loop.

Usage

<?php loop_items(); ?>

Arguments

None

Examples

Default code on items/browse.php

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

<?php while (loop_items()): ?>
 
    <h3><?php echo link_to_item(item('Dublin Core', 'Title'), array('class'=>'permalink')); ?></h3>
 
<?php endwhile; ?>

Looping Items Elsewhere

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

<?php set_items_for_loop(recent_items(10)); ?>
<?php if (has_items_for_loop()): ?>
    <ul class="items-list">
    <?php while (loop_items()): ?>
        <li class="item">
    	    <h3><?php echo link_to_item(); ?></h3>
            <?php if($desc = item('Dublin Core', 'Description', array('snippet'=>150))): ?>
            <div class="item-description"><?php echo $desc; ?></div>
            <?php endif; ?>		
    	</li>		
    <?php endwhile; ?>
    </ul>
<?php else: ?>
    <p>No recent items available.</p>
<?php endif; ?>

Browsing specific item types with specific metadata

If you would like to create a browse view that calls a specific item type containing specific metadata. For example, create a browse page with only Still Images with the Original Format field with the text, Map:

<?php if (item_has_type('Still Image') && item('Item Type Metadata', 'Original Format')== 'Map'): ?>