How can I get a list of public collections and their links in my footer.php
? Seems like it should be simple, but I can't figure it out.
loop('collections')
gives me a `Zend_View_Exception
(An array of records is not available for the loop.).`
Using version 2.2.2.
This is as close as I have come. There must/might be a better way.
$collections = get_records(
'Collection',
array(
'sort_field' => 'id',
'sort_dir' => 'a'
)
);
$links = array();
foreach ($collections as $collection) {
array_push(
$links,
link_to_items_in_collection(
metadata(
$collection,
array('Dublin Core', 'Title')
),
array(
'class' => 'nav__link nav--section__link'
),
'browse',
$collection
)
);
}
For example, there is probably a way to have get_records
sort by title
.
And here is a way to have get_records sort by title
:
$collections = get_records(
'Collection',
array(
'sort_field' => 'Dublin Core,Title',
'sort_dir' => 'a'
)
);
Here's an example that might come closer. I put this in footer.php
. The parameters for get_records
you seem to have a solid handle on!
<?php
$collections = get_records('Collection');
set_loop_records('collections', $collections);
?>
<ul>
<?php foreach (loop('collections') as $collection): ?>
<li><?php echo link_to_collection(); ?></li>
<?php endforeach; ?>
</ul>
That gives a list of collections with links, and seems to get at what you need, unless there are variations I don't see.
Thanks for the more elegant solution.