The most things are possible with Item Manager you just have to know how to do it.
I have thoroughly tested the 'sortby' functionality of IM and can say that it worked fine. It seems to me that you have done something wrong. By the way, the function should called:
and not
Ok, I'll show you a quick example:
Our goal is to get latest 10 items per category and show them in descending order.
1. Create your categories, we call it 'fruits' and 'vegetables'
2. You will need at least one field (in both categries) we call it 'sort_by_date'
3. You can now create your Items
In your case the Controller-Component should look as shown below
categorie_lister
to call controller in frontend you can use DynPages-Plugin:
{% categorie_lister 10 DESC %}
The first parameter is the number of Items to show per category and the second is the sort by option.
And if you did this correctly the output should looks something like this:
I have thoroughly tested the 'sortby' functionality of IM and can say that it worked fine. It seems to me that you have done something wrong. By the way, the function should called:
Code:
ImModel::setPref('sortby', 'title')
and not
Code:
ImModel::setPref('gsortby', 'title').
Ok, I'll show you a quick example:
Our goal is to get latest 10 items per category and show them in descending order.
1. Create your categories, we call it 'fruits' and 'vegetables'
2. You will need at least one field (in both categries) we call it 'sort_by_date'
3. You can now create your Items
In your case the Controller-Component should look as shown below
categorie_lister
PHP Code:
<?php
// get our controller parameter
global $args;
// check if order is desc
$order = ( isset($args[1]) && strtolower($args[1]) == 'desc' ) ? true : false;
// get number of items displayed per category
$items_per_cat = isset($args[0]) ? $args[0] : 10;
// define output
$output = '';
// initialize controller
$manager = new ImController();
// get IManager preferences
$preferences = imModel::getPref();
/*
* Register our templates
* 1. Wrapper
* 2. Row-Element template
*/
$manager->tplRegister(array(
'cat-wrapper' =>
'<div class="cat-wrapper"><h3>[[ cat ]] <span>([[ item-count ]])</span></h3>[[ item-element ]]</div>',
'item-element' =>
'<div class="item"><p>[[ title ]]</p><p>Characteristics: [[ characteristics ]]</p><p>Date: [[ date ]]</p></div>'
)
);
foreach($preferences->categories->category as $cat)
{
// setup items by category
ImCategory::setCategory($cat);
ImModel::setPref('sortby', 'sort_by_date');
$manager->runModelMethod( 'gen_register',
array('sort_by_date', 'characteristics')
);
// Check order
// DESC
if($order)
$items = array_reverse($manager->getModelValue('items_ordered_struct'));
// ASC
else
$items = $manager->getModelValue('items_ordered_struct');
// get number of items per categorie
$item_count = count($items);
$ipc = ($item_count > $items_per_cat) ? $items_per_cat : $item_count;
$row = '';
for($i = 0; $i < $ipc; $i++)
{
// Render your row template
$row .= $manager->paint('item-element',
array('title' => $items[$i]['title'], ' characteristics' => $items[$i]['characteristics'], 'date' => $items[$i]['sort_by_date'])
);
}
// Render wrapper template
$output .= $manager->paint('cat-wrapper',
array('item-count' => $item_count, 'cat' => $cat, 'item-element' => $row)
);
}
echo $output;
?>
to call controller in frontend you can use DynPages-Plugin:
{% categorie_lister 10 DESC %}
The first parameter is the number of Items to show per category and the second is the sort by option.
And if you did this correctly the output should looks something like this: