- Posts: 140
COMMUNITY FORUM
Next & Previous link order is all scrambled?
- Uzi
-
Topic Author
- Offline
- Premium Member
I have a problem regarding the next and previous links that are below an item.
It's a weird thing, the next and previous links are not taking the article order into account? The next and previous links are all scrambled, it's not like the order it's on the front page. The order is all weird. How can I change this?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
The Next / Previous links are the next (and previous) items within the same category.
Please Log in or Create an account to join the conversation.
- Uzi
-
Topic Author
- Offline
- Premium Member
- Posts: 140
I have an article with ID 13594, the next and previous link give me the following article ID's: 13272 and 13263
These are not even remotely close to being the next or previous link. Is it possible it has something to do when you copy articles? That is the only thing I can make up as a possible reason.
It's supposed to be: 13595 and 13593
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Please Log in or Create an account to join the conversation.
- Uzi
-
Topic Author
- Offline
- Premium Member
- Posts: 140
Krikor wrote: Do these items belong to the same category?
Yes, these are articles in the same category.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
github.com/getk2/k2/blob/master/components/com_k2/models/item.php#L1847-L1854
Please Log in or Create an account to join the conversation.
- Uzi
-
Topic Author
- Offline
- Premium Member
- Posts: 140
Krikor wrote: It will pull the next item from the same category if there is no ordering value. Otherwise it will respect the component's ordering.
github.com/getk2/k2/blob/master/components/com_k2/models/item.php#L1847-L1854
Hmm, it's still not working. I have a category which is sorted by publication date. Now the previous and next links are not working correctly, it looks like it's not using the publication date, but maybe the ID or something? I cannot find the sorting it's using now. It looks like it's all scrambled.
EDIT: Ok, I think I found something. Which is, if I get the articles to order by publish date I think it can work. I think the ordering of the articles for the next and previous links are not the same as how I configured the rest, namely by date.
EDIT 2: I found it. It uses the ordering of the items in the k2 items manager. Always. So there has to be a core hack for to fix it, and sort it by date.
Please Log in or Create an account to join the conversation.
- Uzi
-
Topic Author
- Offline
- Premium Member
- Posts: 140
Yuzi wrote:
Krikor wrote: It will pull the next item from the same category if there is no ordering value. Otherwise it will respect the component's ordering.
github.com/getk2/k2/blob/master/components/com_k2/models/item.php#L1847-L1854
Where can I configure the ordering of the items? I cannot find it in the category itself...?
Found it! It's in the menu options.
Hmm, it's still not working. I have a category which is sorted by publication date. Now the previous and next links are not working correctly, it looks like it's not using the publication date, but maybe the ID or something? I cannot find the sorting it's using now. It looks like it's all scrambled.
EDIT: Ok, I think I found something. Which is, if I get the articles to order by publish date I think it can work. I think the ordering of the articles for the next and previous links are not the same as how I configured the rest, namely by date.
EDIT 2: I found it. It uses the ordering of the items in the k2 items manager. Always. So there has to be a core hack for to fix it, and sort it by date.
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.
Please Log in or Create an account to join the conversation.
- Uzi
-
Topic Author
- Offline
- Premium Member
- Posts: 140
www.joomlaworks.net/forum/k2-en/45668-item-navigation-order-alphabetically
Cannot seem to make it work by hacking the core code..
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
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?
Please Log in or Create an account to join the conversation.
- Uzi
-
Topic Author
- Offline
- Premium Member
- Posts: 140
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?
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.
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
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.
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.
Please Log in or Create an account to join the conversation.