Keyword

Item Navigation Order

  • Alberto Lagos
  • Alberto Lagos's Avatar Topic Author
  • Offline
  • New Member
More
11 years 10 months ago #107490 by Alberto Lagos
Item Navigation Order was created by Alberto Lagos
Hello,

I have a menu item pointing to a k2 Category (News), where there are like 40 items.

I have set the order of the items inside the category to Last Created Item first, so I can see the last item in first place. If I go thru the 4 pages that appear under menu News, I can see the items ordered as they should be.

My concern comes when I am browsing thru the news. I would like that someone reading the news could go from the first one to the last one following the order I established in Category options, and in the same order they are laid down under the menu.

But I am not getting this, and reading the code, it seems to me that they are just ordered by ordering column!

Is anyone else having this issue? I have seen that yes, but no solution nor people complaining much.

I am porting my website from previous design, and have introduced the items randomly. There are only 40 items, I could order them, but really would prefer that they should be ordered correctly as per category order.

Thanks and Regards

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

More
11 years 7 months ago #107491 by Nils
Replied by Nils on topic Re: Item Navigation Order
Same question here. Any hints on this?

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

More
11 years 7 months ago - 11 years 7 months ago #107492 by Nils
Replied by Nils on topic Re: Item Navigation Order
Found a solution:

You have to change two files:

in /components/com_k2/views/item/view.html.php about line 273 in

Change
$nextItem = $model->getNextItem($item->id, $item->catid, $item->ordering);

to
$nextItem = $model->getNextItem($item->id, $item->catid, $item->ordering, $item->publish_up);

Change
$previousItem = $model->getPreviousItem($item->id, $item->catid, $item->ordering);

to
$previousItem = $model->getPreviousItem($item->id, $item->catid, $item->ordering, $item->publish_up);


in /components/com_k2/models/item.php about line 1392 in

Change
function getPreviousItem($id, $catid, $ordering)
to
function getPreviousItem($id, $catid, $ordering, $publish_up)

Change
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 ordering 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 ordering DESC";
}

to
/*
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 ordering 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 ordering DESC";
}
*/

$query = "SELECT * FROM #__k2_items WHERE id != {$id} AND catid={$catid} AND published=1 AND publish_up >= '".$publish_up."' 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 publish_up ASC";


Change
function getNextItem($id, $catid, $ordering)

to
function getNextItem($id, $catid, $ordering, $publish_up)

Change
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 ordering ASC";
}
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 ordering ASC";
}

to
/*
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 ordering ASC";
}
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 ordering ASC";
}
*/

$query = "SELECT * FROM #__k2_items WHERE id != {$id} AND catid={$catid} AND published=1 AND publish_up < '".$publish_up."' 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 publish_up DESC";



This should do the trick. For me it works.

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

More
11 years 6 months ago #107493 by snlr
Replied by snlr on topic Re: Item Navigation Order
This works for me too.

Thank you for providing this essential feature.

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

More
11 years 3 days ago #107494 by Andrew Paterson
Replied by Andrew Paterson on topic Re: Item Navigation Order
Does anyone know if it's possible to do this with a template override, and if so what the folder structure in your template is?

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


Powered by Kunena Forum