Keyword

Next & Previous link order is all scrambled?

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 9 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
6 years 9 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?

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 9 months ago - 6 years 9 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: 6 years 9 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
6 years 9 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.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 9 months ago - 6 years 9 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: 6 years 9 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
6 years 9 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.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 9 months ago - 6 years 9 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: 6 years 9 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
6 years 9 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.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 9 months ago - 6 years 9 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: 6 years 9 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
6 years 9 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.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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


Powered by Kunena Forum