- Posts: 438
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- K2 Power Tip: Change Related Items Order to Random - K2 Hack
K2 Power Tip: Change Related Items Order to Random - K2 Hack
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
9 years 10 months ago #143806
by Joe Campbell
K2 Power Tip: Change Related Items Order to Random - K2 Hack was created 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...
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
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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 years 10 months ago #143820
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
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.
If you set a limit to the items, then you won't have any issues.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
9 years 10 months ago #143825
by Joe Campbell
Replied by Joe Campbell on topic K2 Power Tip: Change Related Items Order to Random - K2 Hack
Thanks for the compliment.
Please provide the code for setting the limit.
Please provide the code for setting the limit.
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Moderator
Less
More
- Posts: 8743
9 years 10 months ago #143870
by Lefteris
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Lefteris on topic K2 Power Tip: Change Related Items Order to Random - K2 Hack
@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.
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.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Forum
- K2 Community Forum
- English K2 Community
- K2 Power Tip: Change Related Items Order to Random - K2 Hack