Keyword

Dual Sorting

  • Ipshwitz
  • Ipshwitz's Avatar Topic Author
  • Offline
  • New Member
More
12 years 8 months ago #61905 by Ipshwitz
Dual Sorting was created by Ipshwitz
So I'm using K2 and loving it, but running into a slight issue that may be something simple. I need the category view to display the Featured Items first (which it does) and then all the other results alphabetically. Is that something that can be done? As it is, there doesn't seem to be a specific order the rest of the items fall into.

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

More
12 years 8 months ago #61906 by william white
Replied by william white on topic Re: Dual Sorting
Just a stab at this one.
The offending (in your case) query is
SELECT i.*, c.name as categoryname,c.id as categoryid, c.alias as categoryalias, c.params as categoryparams
  FROM dtgku_k2_items as i
  LEFT JOIN dtgku_k2_categories AS c
  ON c.id = i.catid
  WHERE i.published = 1
  AND i.access IN(1,1)
  AND i.trash = 0
  AND c.published = 1
  AND c.access IN(1,1)
  AND c.trash = 0
  AND ( i.publish_up = '0000-00-00 00:00:00' OR i.publish_up <= '2012-01-27 05:17:28' )
  AND ( i.publish_down = '0000-00-00 00:00:00' OR i.publish_down >= '2012-01-27 05:17:28' )
  AND c.id IN (1)
  ORDER BY i.featured DESC, i.created[b] DESC[/b]
  LIMIT 0, 14
The desc tag in the second order needs to be changed
just a starting point

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

More
12 years 5 months ago - 12 years 5 months ago #61907 by promobit
Replied by promobit on topic Re: Dual Sorting

William White wrote: Just a stab at this one.
The offending (in your case) query is

SELECT i.*, c.name as categoryname,c.id as categoryid, c.alias as categoryalias, c.params as categoryparams
  FROM dtgku_k2_items as i
  LEFT JOIN dtgku_k2_categories AS c
  ON c.id = i.catid
  WHERE i.published = 1
  AND i.access IN(1,1)
  AND i.trash = 0
  AND c.published = 1
  AND c.access IN(1,1)
  AND c.trash = 0
  AND ( i.publish_up = '0000-00-00 00:00:00' OR i.publish_up <= '2012-01-27 05:17:28' )
  AND ( i.publish_down = '0000-00-00 00:00:00' OR i.publish_down >= '2012-01-27 05:17:28' )
  AND c.id IN (1)
  ORDER BY i.featured DESC, i.created[b] DESC[/b]
  LIMIT 0, 14
The desc tag in the second order needs to be changed
just a starting point



In which file?

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

More
12 years 3 months ago - 12 years 3 months ago #61908 by promobit
Replied by promobit on topic Re: Dual Sorting
Ok, it is in
components/com_k2/models/itemlist.php

A question:
is it possible to have this ordering: featured RAND() and created RAND()?

For example, i tried
$orderby = 'i.featured,RAND(),i.created';

and it works, buit there arer created first and then featured.
I wish the inverse, but if i try
$orderby = 'i.created,RAND(),i.featured';
--> it doesn't work

How could I do ?

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

More
12 years 3 months ago - 12 years 3 months ago #61909 by matthew turner
Replied by matthew turner on topic Re: Dual Sorting
Hi promobit,
Your syntaxt looks wrong to me - too many commas, although I have not used RAND() for any recent projects - mostly only DESC or ASC...

You have :

$orderby = 'i.featured,RAND(),i.created';

This should be :

$orderby = 'i.featured RAND(),i.created RAND()';

Hope this helps
Regards
Mat

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


Powered by Kunena Forum