Keyword

k2 related items in category_item.php

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
8 years 3 months ago - 8 years 3 months ago #155614 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic Module to show related K2 items
Hello,

I have tried to make the hack as minimal as possible, here is it:

Edit components/com_k2/views/itemlist/view.html.php, find this code snippet:
else
			{
				$items[$i] = $model->prepareItem($items[$i], $view, $task);
			}

Insert this snippet directly after the above one:
if (isset($items[$i]->tags) && count($items[$i]->tags))
			{
				$itemListModel = $this->getModel('itemlist');
				$items[$i]->relatedItems = count($itemListModel->getRelatedItems($items[$i]->id, $items[$i]->tags, $items[$i]->params));
			}

Then you can use this line anywhere in category_item.php to display the related items count
<?php if(isset($this->item->relatedItems)) { echo " Related Items(" .$this->item->relatedItems . ")"; } ?>

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Last edit: 8 years 3 months ago by Mohamed Abdelaziz.

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

More
8 years 3 months ago #155664 by jim
Replied by jim on topic Module to show related K2 items
Hi Mohamed,

Firstly thanks so much for this, very kind of you, much appreciated and also sorry for the delay in my response.

I very much hoped to only be thanking you, but im afraid to say (after checking everything 3 times) im afraid to say it isn't working for me.

If you have any ideas why it itsn't working, id very much appreciate your time and help, thanks again so much!!!!!! :)

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
8 years 3 months ago #155671 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic Module to show related K2 items
Hi jim,
Do you find any error? If yes, what is the message?
Also make sure the related items parameter is set to Show in the category configuration.

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

More
8 years 3 months ago - 8 years 3 months ago #155675 by jim
Replied by jim on topic Module to show related K2 items
Hi Mohamed,
Thanks again for this, much appreciated!!! :)

Sorry I should have turned on error reporting and included this error in my previous post (sorry about that!) here is the error:

Undefined property: stdClass::$relatedItems in <b>/templates/my-template/html/com_k2/templates/properties/category_item.php</b> on line <b>25

Also yes the related items parameter is set to show and related iems are being displayed on the single items pages.

Once again thanks so much for your time and help on this Mohamed!!! Really really appreciate it!!! :)
Last edit: 8 years 3 months ago by jim.

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

More
8 years 3 months ago #155720 by jim
Replied by jim on topic Module to show related K2 items
Hi Mohamed,

So sorry to post again so soon, am just desperate to get this job finished (this is the last thing I have left to complete).

I just wondered if you have any ideas what might be wrong from the errors?

Once again any help would be very very much appreciated!

Many thanks Mohamed!!!

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
8 years 3 months ago #155771 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic Module to show related K2 items
Hi Jim,

I have it already working on my local website!
As long as you applied the modifications as described, I think it is a configuration issue, all relevant Related Items parameters have to be set to Show.

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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


Powered by Kunena Forum