Keyword

Next & Previous link order is all scrambled?

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
7 years 10 months ago - 7 years 10 months ago #162629 by Uzi
Hello,

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?
Last edit: 7 years 10 months ago by Uzi.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #162632 by Krikor Boghossian
Replied by Krikor Boghossian on topic Next & Previous link only main category?
Hello,

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
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
7 years 10 months ago #162633 by Uzi
Yeah but what is the next one? The next ID? The next one based on creation date?

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #162635 by Krikor Boghossian
Replied by Krikor Boghossian on topic Next & Previous link only main category?
Do these items belong to the same category?

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

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
7 years 10 months ago #162640 by Uzi

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #162656 by Krikor Boghossian
Replied by Krikor Boghossian on topic Next & Previous link only main category?
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

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

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
7 years 10 months ago - 7 years 10 months ago #162658 by Uzi

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.
Last edit: 7 years 10 months ago by Uzi.

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

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
7 years 10 months ago #162660 by Uzi

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
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
7 years 10 months ago #162663 by Uzi
Anyone got an idea? I found an old topic regarding this issue, but that is 3-4 years ago.

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #162685 by Krikor Boghossian
Replied by Krikor Boghossian on topic Next & Previous link order is all scrambled?

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
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
7 years 10 months ago #162698 by Uzi

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #162710 by Krikor Boghossian
Replied by Krikor Boghossian on topic Next & Previous link order is all scrambled?
Did you use ORDER BY publish_up DESC;
What was the result?

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

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
7 years 10 months ago - 7 years 10 months ago #162893 by Uzi
I did, and it gets all weird. I don't know what is happening, I really don't. I cannot seem to get the logic behind it, if I order it by ID it just randomly skips over articles, it only seems to work with the standard ordering, because its probably hardcoded to work with ordering only. Maybe I have to rewrite the database query?

Maybe a core hack?
Last edit: 7 years 10 months ago by Uzi.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #162926 by Krikor Boghossian
Replied by Krikor Boghossian on topic Next & Previous link order is all scrambled?
Keep in mind that only items within the same category will be displayed.
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
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
7 years 10 months ago - 7 years 10 months ago #162939 by Uzi
Can I change this so it gets based on publish up?

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.
Last edit: 7 years 10 months ago by Uzi.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #162948 by Krikor Boghossian
Replied by Krikor Boghossian on topic Next & Previous link order is all scrambled?
Yes, basically instead of: id < {$id} you can use your own criteria.

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

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
7 years 10 months ago - 7 years 10 months ago #162966 by Uzi
Yes, I understand that for my query I need to overhaul the criteria but it can never work the way I want with the current query.

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.
Last edit: 7 years 10 months ago by Uzi.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #162975 by Krikor Boghossian
Replied by Krikor Boghossian on topic Next & Previous link order is all scrambled?
I have not tried it, but I think
$date = JFactory::getDate($item->modified);
will work.
Instead of modified you can use created or published.

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

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
7 years 10 months ago - 7 years 10 months ago #162986 by Uzi
Thanks,

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.
Last edit: 7 years 10 months ago by Uzi.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #162996 by Krikor Boghossian
Replied by Krikor Boghossian on topic Next & Previous link order is all scrambled?
$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.


Powered by Kunena Forum