Keyword

Latest Items from One or More Categories (change order?)

  • krmr
  • krmr's Avatar Topic Author
  • Offline
  • Senior Member
More
1 year 9 months ago #180769 by krmr
Hello to the great community,

I have an unusual question: I want to use the possibilities of "Latest Items" k2 menu type (the fact that it is the only way to have a layout of ordered categories and then items listed under each category) but I need to show the items in each category ordered alphabetically.
Is this possible on the level of my subtemplate?

Please Log in or Create an account to join the conversation.

More
1 year 8 months ago #180798 by JoomlaWorks
I'm afraid there is no such sorting option for the items.

That's because the point for this view was to display a bunch of authors or categories and their latest items, in the first place.

You can adapt it of course, but it would require hacking the relevant model to change the SQL query.

Change this line:

github.com/getk2/k2/blob/d0c84174ea9c07b80675b62daa028fce1612085c/components/com_k2/models/itemlist.php#L560

to
            ORDER BY i.title ASC";

And change this line:

github.com/getk2/k2/blob/ab1049dee37150afc854be6ff1ca8840e405cfa2/components/com_k2/views/latest/view.html.php#L120

From
$category->items = $model->getData('rdate');

to
$category->items = $model->getData('alpha');

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • krmr
  • krmr's Avatar Topic Author
  • Offline
  • Senior Member
More
1 year 8 months ago #180812 by krmr
Thanks so much for your help!

I know it is highly unusual request, but using the "latest items" layout I am able to have under one menu list of continents and under each continent list of cities in alphabetical order.

I actually inserted this into my overridden template latest.php, at the Items List query and it worked.
<?php
usort($block->items, function($a, $b) {
return strcmp($a->title, $b->title);
});

foreach ($block->items as $item) {
K2HelperUtilities::setDefaultImage($item, 'latest', $this->params);
$this->item = $item;
echo $this->loadTemplate('item');
}
?>

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum