2017-01-04, 08:54:42
(2015-05-22, 00:42:40)Bigin Wrote: 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->category->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.
Hello and thank you for your great plug in,
I've tried your example but with no success so far... I copied your code into my template but I get the following error:
PHP Code:
Notice: Undefined property: IManager::$category in D:\xampp\htdocs\test-gs\theme\Mode\item-details.php on line 51
Fatal error: Call to a member function getCategory() on a non-object in D:\xampp\htdocs\test-gs\theme\Mode\item-details.php on line 51
What do I do wrong?
Thank you in advance.