Hello,
hmmm... OK.
If you only try to show last 5 items sorted by release date, you can use this function in your functions.php file for example:
And your Controller might then look like this:
By the way, it's not necessary to register standard fields like "title" or "date", etc, you should do it only if you use custom fields like "tresc":
Better:
To dispay all standard fields of your items just use:
Regards
(2014-06-16, 19:24:12)xxdex Wrote: it's possible to get only 5 item's from all categories sorted by date..
without a categories. only 5 last added items...
i'm using a functions.php file in template folder
and i'm loading this function by template... it's working..
please help.. thank you in advance
hmmm... OK.
If you only try to show last 5 items sorted by release date, you can use this function in your functions.php file for example:
PHP Code:
function sort_array($a, $b)
{
if ($a['date'] == $b['date'])
{
return 0;
}
else
{
if($a['date'] < $b['date'])
{
return 1;
}
else
{
return -1;
}
}
}
And your Controller might then look like this:
PHP Code:
// get max number of items displayed
$items_max = 5;
// initialize controller
$manager = new ImController();
// get IManager preferences
$preferences = imModel::getPref();
$items_arr = array();
foreach($preferences->categories->category as $cat)
{
// setup items by category
ImCategory::setCategory($cat);
$manager->runModelMethod('gen_register');
// get all your items no matter what category
$items = $manager->getModelValue('items_ordered_struct');
$items_arr = array_merge($items_arr, $items);
}
$item_count = count($items_arr);
$ipc = ($item_count > $items_max) ? $items_max : $item_count;
// There your "sort_array" function call
usort($items_arr, 'sort_array');
for($i = 0; $i < $ipc; $i++)
{
echo '<strong>Published on:</strong> ' . $items_arr[$i]['date'] . ' <strong>Title:</strong> ' . $items_arr[$i]['title'] . '<br />';
}
By the way, it's not necessary to register standard fields like "title" or "date", etc, you should do it only if you use custom fields like "tresc":
(2014-06-16, 19:24:12)xxdex Wrote: $manager->runModelMethod( 'gen_register',
array('title', 'tresc')
);
Better:
PHP Code:
$manager->runModelMethod( 'gen_register', array('tresc'));
To dispay all standard fields of your items just use:
PHP Code:
$items = $manager->getModelValue('items_ordered_struct');
var_dump($items);
Regards