Keyword

k2 content module - show items except current item

  • Kogos Grain
  • Kogos Grain's Avatar Topic Author
  • Offline
  • New Member
More
7 years 3 months ago #159504 by Kogos Grain
i am using k2 content module to randomly show 2 k2 items in the item-view page. However, i want to exclude the item that is actually seen in the page.

I got the current item id with JRequest::getInt('id') and itemid showing in module with $item->id, but i'm banging my head through a wall here.

What i did so far was use an if statement in the foreach loop of the module:
<?php if (JRequest::getInt('id') == $item->id) {
continue;
}?>

...but the problem is that if the current item exists in the loop, it won't use another item. So, if i want to show 2 items in the module, and one of them is the item i'm actually reading in the item-view page, it will skip it but show only one item.

Is there any way to achieve it?

I was also thinking of checking if the item exists in the foreach loop, then change count($items), but that's a lot of mess. I think there is a more "clean" way of doing this, i just can't figure this out.

Thanks in advance!

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


Powered by Kunena Forum