(2015-05-21, 20:54:36)Tyblitz Wrote: Being a front-end developer with only some PHP knowledge, looking at the examples it seemed not 'very automatic' or self-explanatory to actually output items.
You are right. I understand what you mean, the description is in fact a bit poor, but that's the reason why I started this thread.
There is another example (it outputs Items in frontend/theme):
Let's say we have a category named 'Fruits' and have created the following fields for it 'color' and 'image'
Next, create 3 fruits with the title: 'Bananas', 'Oranges', 'Cherries'
color field values: 'yellow', 'orange', 'red'
and finally upload three pictures.
Now you go to your theme and add this code there:
PHP Code:
<?php
// get ItemManager instance
$manager = new IManager();
// check ItemManager installed
if(!$manager){die('ItemManager not installed!');}
// get ImCategory instance
$fruitsCategory = $manager->getCategoryMapper()->getCategory('name=Fruits');
// check Fruits category exists
if(!$fruitsCategory){die('Fruits category does not exist!');}
// get ImItems class instance
$itemClass = $manager->getItemClass();
// initialise all items of the category Fruits
$itemClass->init($fruitsCategory->get('id'));
/********** That's all, now we can work with Items! **********/
// Now, all your item data in: $itemClass->items Object
foreach($itemClass->items as $item)
{
// Output item name
echo 'Item Name: ' . htmlspecialchars($item->name) . ' ';
// Output image Nr 1
if(!empty($item->fields->image->imagefullurl[0]))
{
echo '<img alt="" src="'. htmlspecialchars($item->fields->image->imagefullurl[0]). '" width="200" >';
}
// output color field value
if(!empty($item->fields->color->value))
{
echo ' Item color: '. htmlspecialchars($item->fields->color->value) . '<br /><br />';
}
}
?>
I do not think that it's very difficult?! Someone with little or no PHP knowledge should be able to vaguely understand that.