The link_to_browse_items()
function will generate the proper HTML for a link to the browse page for items, with any appropriate filtering parameters passed to the URL.
Usage
<?php echo link_to_browse_items($text, $browseParams, $linkProperties); ?>
Arguments
- string $text (required) - Text to display in the link.
- array $browseParams (optional) - Any parameters to use to build the browse page URL, e.g.
array('collection' => 1)
would render items/browse?collection=1 as the URL. - array $linkAttributes (optional) - An array of XHTML attributes to assign to the link.
Examples
Changing Text of the Link
To link to the items/browse page, pass a value to the first argument in the function:
<?php echo link_to_browse_items('Browse Items'); ?>
This will generate:
<a href="http://example.com/items/browse">Browse Items</a>
Using Browse Parameters
To generate a link to browse all items that have been marked 'featured', for example, we'll need to pass an array to the second argument, with the appropriate parameters for sorting. To create a link for only featured items, use the following:
<?php echo link_to_browse_items('Browse Featured Items', array('featured' => 1)); ?>
This will generate:
<a href="http://example.com/items/browse?featured=1">Browse Featured Items</a>
Using Link Attributes
The third argument of the link_to_browse_items()
function lets you add other attributes to the a
tag for the browse link.
<?php echo link_to_browse_items('Browse Featured Items', array('featured' => 1), array('id' => 'featured-items-link')); ?>
This will generate:
<a id="featured-items-link" href="http://example.com/items/browse?featured=1">Browse Featured Items</a>
You can pass any attribute valid for the a
tag.