Functions/item_belongs_to_collection

item_belongs_to_collection checks whether an item belongs to a collection. Returns true or false.

Usage

<?php
    item_belongs_to_collection($name, $item);
?>

Arguments

string $name (optional)
Name of the collection to check for. By default, checks if the item belongs to any collection.
Default: null
Item $item (optional)
Item to check. By default, the current item is used.
Default: null

Examples

The following example, taken from the default theme's items/show.php file, will display the collection name if the item belongs to a collection:

<?php if ( item_belongs_to_collection() ): ?>
    <div id="collection" class="element">
        <h3>Collection</h3>
        <div class="element-text">
          <p><?php echo link_to_collection_for_item(); ?></p>
        </div>
    </div>
<?php endif; ?>