In Simple Pages / Plugin's view loop('item') and equivalents throws 404

Whenever I put loop('item'), loop('items'), loop('Item') or
loop('Items') in my code, be it a SimplePage or a plugin's views,
Omeka throws a "404 Page Not Found" error. Why is that, and what can I
do to fix it?

There might be two (or more) things going on.

First, the first parameter to loop() is the name of a record type in Omeka, with records of that type being set on the page in the controller. Commonly this is part of the url path. So on /items/browse it will be looping through items. On other pages, different record types would be sent to the page, depending on the plugin. For SimplePages, it would be loop('simple_pages_page')

However, if that were the only thing going on, I would have expected this error message:

An array of records is not available for the loop.

Are there any other changes you have made?

Thanks patrickmj for your answer!
I really appreciate it.
I'm struggling with that issue for hours.

Here are the code-example for the SimplePages:
The slug for this SimplePages page is "postkarten".

The first section is for Omeka 1.5 and works as expected.

But how can i fix that Code for Omeka 2?

There are a couple things to adjust for 2.0. However, nothing I see there explains the 404. Is it possible that the page isn't published, and you are looking at it without being logged in?

In starting the loop, since you dug up the $items earlier, you can pass those into loop:

foreach (loop('Item', $items) as $item):

Then, you won't need to try to look up the $item or try to set it again. You can just use that variable.

Instead of item() to look up metadata in 2.0, use

metadata($item, array('Dublin Core', 'Title')

Similarly, you can no pass in the record for all_element_texts:


An optional second parameter lets you pass in that array of options. I'm pretty sure it works the same, but not 100% sure.

I'm coming across the 404 as well, but from a different angle.

The codex says that loop('items') replaces loop_items_in_collection(), but after setting the collection, loop('items') throws a 404.

Really, all I need to do is get the id (or object) of the first item in the collection, so if there's a better way, I'm all for it.


Your 2.0 code doesn't include anything to account for the 1.5 code's set_items_for_loop($items). Since you're using loop('Item'), you want to use set_loop_records('Item', $items) in the place of set_items_for_loop for 2.0.


Your problem is similar: you need to use get_records('Item', array('collection' => $collectionId)) to get the Items in the collection, and then set them for the loop with set_loop_records before you can use loop.