Keyword

K2 Power Tip: Change Related Items Order to Random - K2 Hack

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
9 years 11 months ago #143806 by Joe Campbell
Don't let site visitors see the same related items. If they do, they might start ignoring that area of your site. This quick & easy hack will randomize the results of your related items.

Note: use caution if your website is extremely large, as this may slow down the rendering of your item pages.

File: components/com_k2/models/itemlist.php

Find the following code...
		$query .= " AND c.trash = 0 
				AND (i.id) IN ({$sql}) 
				ORDER BY i.created DESC";

Replace ORDER BY i.created DESC"; >>> with >>> ORDER BY RAND()";
resulting in the following code:

$query .= " AND c.trash = 0
AND (i.id) IN ({$sql})
ORDER BY RAND()";

Special thanks to www.joomreem.com (@JoomReem) for helping with this hack

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 11 months ago #143820 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 Power Tip: Change Related Items Order to Random - K2 Hack
This is nice Joe.
If you set a limit to the items, then you won't have any issues.

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

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
9 years 11 months ago #143825 by Joe Campbell
Thanks for the compliment.

Please provide the code for setting the limit.

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

More
9 years 11 months ago #143870 by Lefteris
@Joseph

The query has already a limit applied ( the number of related items you want to show ) .

It's the random ( RAND() function ) implementation of MySQL that takes that much time since it needs to parse all entries in the table.

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


Powered by Kunena Forum