- Posts: 140
COMMUNITY FORUM
Next & Previous link order is all scrambled?
- Uzi
- Topic Author
- Offline
- Premium Member
Krikor wrote:
Ok I tried to change the item.php model to change the getPreviousItem method. But if I use the publish_up instead of ordering to sort, it's not working as intended.
Can you send me the code you used?
Yes. I changed the following code:
if ($ordering == "0")
{
$query = "SELECT * FROM #__k2_items WHERE id < {$id} AND catid={$catid} AND published=1 AND ( publish_up = ".$db->Quote($nullDate)." OR publish_up <= ".$db->Quote($now)." ) AND ( publish_down = ".$db->Quote($nullDate)." OR publish_down >= ".$db->Quote($now)." ) {$accessCondition} AND trash=0 {$languageCondition} ORDER BY id DESC";
}
else
{
$query = "SELECT * FROM #__k2_items WHERE id != {$id} AND catid={$catid} AND ordering < {$ordering} AND published=1 AND ( publish_up = ".$db->Quote($nullDate)." OR publish_up <= ".$db->Quote($now)." ) AND ( publish_down = ".$db->Quote($nullDate)." OR publish_down >= ".$db->Quote($now)." ) {$accessCondition} AND trash=0 {$languageCondition} ORDER BY id DESC";
}
This is the previousItem function in the model item.php file.
The best solution is to order by publish date but for some reason it doesn't work as intented.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
- Posts: 15920
What was the result?
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Uzi
- Topic Author
- Offline
- Premium Member
- Posts: 140
Maybe a core hack?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
- Posts: 15920
gist.github.com/kricore/524bebc25ec650ecd36aa471903e7477
This is a hack so I recommend against using it, and using this as a starting point for a K2 plugin.
This query completely disregards the item's ordering and publish date and will fetch the items based on their IDs.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Uzi
- Topic Author
- Offline
- Premium Member
- Posts: 140
ok, so this is working all way better than the default code. Now the default code actually removes the next link if there aren't any newer articles, while this code doesn't do that. Is it possible to implement that in coding or can't that be done without actually using the ordering tag.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Uzi
- Topic Author
- Offline
- Premium Member
- Posts: 140
EDIT: I got the query figured out. Is there a possibility to get the current publish_up from the current article, and other attributes from the article, I don't have enough data with only the id, catid and ordering.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
- Posts: 15920
$date = JFactory::getDate($item->modified);
Instead of modified you can use created or published.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Uzi
- Topic Author
- Offline
- Premium Member
- Posts: 140
but how can I get the $item? Because I only have the ID, CATID and ordering available in the method, so I guess I need to get the item based on ID first? And by item I mean the K2 item.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
- Posts: 15920
$item = K2ModelItem::getData();
Then you can use:
$item->publish_up
or even better you can use var_dump() or print_r() to see the item's data.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.