The get_items()
helper allows you to retrieve an array of items matching several arguments. You can then use this array in set_items_for_loop to create a custom loop of items.
Usage
<?php get_items( $params = array(), $limit ); ?>
Arguments
- params - An array of parameters. Available parameters include:
- collection - Collection ID
- featured - true or false
- range - A range of item IDs
- recent - true or false
- tags - A string of comma-separated tags
- type - Type ID
- user - User ID
- sort_field (see Sorting Results)
- sort_dir (see Sorting Results)
- limit - The maximum number of items you want to return. The default value is '10'.
Examples
Recent Items
<?php $items = get_items(array('recent' => true)); set_items_for_loop($items); while(loop_items()): ?> <h2><?php echo item('Dublin Core', 'Title'); ?></h2> <p><?php echo item('Dublin Core', 'Description'); ?></p> <?php endwhile; ?>
You can also use the recent_items helper.
Three Featured Items
The following uses get_items
helper to create a loop of the last 3 items marked "featured".
<?php $items = get_items(array('featured' => true)); set_items_for_loop($items); while(loop_items()): ?> <h2><?php echo item('Dublin Core', 'Title'); ?></h2> <p><?php echo item('Dublin Core', 'Description'); ?></p> <?php endwhile; ?>
Last 20 items tagged "foo" and "bar"
The following uses get_items
helper to create a loop of the last 20 items tagged "foo" and "bar".
<?php $items = get_items(array('tags' => 'foo,bar'), 20); set_items_for_loop($items); while(loop_items()): ?> <h2><?php echo item('Dublin Core', 'Title'); ?></h2> <p><?php echo item('Dublin Core', 'Description'); ?></p> <?php endwhile; ?>