Functions/link to collection for item

The link_to_collection_for_item helper will generate a link to the collection to which an item belongs. The title of the collection is used as the text for the link.

Usage

<?php link_to_collection_for_item(
        $text = null, 
        $props = array(), 
      );
?>

Arguments

  • text - (string) The string of text for the link. Default is null. If null, the title of the collection is used.
  • props - (array) An array of properties for the advanced search link. These are attributes and values for the <a> tag.

Examples

Change the text of the link

You can use any string of text for the link to the item's collection by specifying it as the first argument:

<?php
echo link_to_collection_for_item('Item Collection'); 
?>
 
This will generate:
 
<source lang="html4strict">
<a href="http://example.com/collections/show/4">Item Collection</a>

Adding Attributes to the Link

You can add attributes to the link, such as id or class, by passing those attributes to the props argument in an array:

<?php 
echo link_to_collection_for_item(
        'Item Collection', 
        array(
            'id' => 'item-collection-link', 
        )
     ); 
?>

This will generate:

<a href="http://example.com/collections/show/4" 
id="item-collection-link">Item Collection</a>

You can add any valid attribute to the link tag.