I am attempting to build a public site by customizing the default theme. I am however, struggling a bit with the new version 2 code. The documentation seems to expect a certain level of knowledge and there are very few samples and examples.
I want to adapt the page "/items/show/??" so that the Next and Last buttons cycle through the items in the collection that the first item belongs to, rather than cycling all the stored items, as the default page currently does. I am using the "Item Order" Plugin and would also like the order of the cycling to be that selected via the Item Order Plugin rather than the order items were entered.
So, I need code to create an array of the items in the selected collection and a method to get the next/last item for each item, according to the Plugin order.
Can anyone help me with some examples or sample code?
The Item Order plugin will let you get an array of the items in a collection, in the correct order, like this:
$orderedItems = get_db()->getTable('ItemOrder_ItemOrder')->fetchOrderedItems($collectionId);
$collectionId you can look up with
It doesn't offer much for digging up the next or previous items, though. I suppose you could loop through that array looking for the item being shown, then get the next and previous from item ids from the next and previous in the array. Then you could change the links as needed.
Once you have the next and previous items from the array, you can create the links like this:
echo link_to($next, 'show', $text);
$next is the next item that you dug up from the array, and
$text is the link text. Similarly for the previous or last or first items.
Hope that helps
Thanks for the prompt reply.
This looks like it will do it. I will post code when I have sorted it out.
Here's my code. It was pretty straightforward in the end.
// get the items in this collection ordered by the order plugin
$orderedItems = get_db()->getTable('ItemOrder_ItemOrder')->fetchOrderedItems(metadata('item', 'Collection Id'));
// loop all items in the selected collection
$nextitem = null; $nextlink = '';
$previtem = null; $prevlink = '';
$current = null;
if (count($orderedItems) != 0)
for ($x = 0; $x <= count($orderedItems); $x++)
if ($orderedItems[$x]['id'] == metadata('item', 'id'))
// found the current item in the list
if ($x != 0)
$nextitem = get_record_by_id('item', $orderedItems[$x - 1]['id']);
if ($x != count($orderedItems)-1)
$previtem = get_record_by_id('item', $orderedItems[$x + 1]['id']);
if ($previtem != null)
$prevlink = link_to($previtem, 'show', 'Previous');
if ($nextitem != null)
$nextlink = link_to($nextitem, 'show', 'Next');