Keyword

k2 related items in category_item.php

More
8 years 10 months ago #155427 by jim
I have the following code which I use within the k2 template file 'item.php'

<?php echo $this->relatedItems[0]->title->value ;?>

Id simply like to use this same code in the k2 template file 'category_item.php'

Ive found the function 'getRelatedItems' in components/com_k2/models/itemlist.php and copied this to components/com_k2/models/item.php but this hasn't helped.

If anyone has any ideas, id really appreciate it thanks!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 10 months ago #155447 by Krikor Boghossian
Replied by Krikor Boghossian on topic k2 related items in category_item.php
Hacking the core is not recommended and can lead to unexpected errors.
The related items are not available in the itemlist views.
I would suggest using an extension or a K2 plugin instead.

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

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

More
8 years 10 months ago - 8 years 10 months ago #155508 by jim
Replied by jim on topic k2 related items in category_item.php
Hi Krikor,
Many thanks for your reply/help!

Could you possibly suggest an extension/k2 plugin that might do the trick? Ive looked but haven't found anything.

Basically, what im aiming to achieve is, simply a count (only the integer) of related items on each item on category view.

Many thanks in advance!
Last edit: 8 years 10 months ago by jim.

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

More
8 years 10 months ago #155521 by Alex B.
Replied by Alex B. on topic Module to show related K2 items

Krikor wrote: I would suggest using an extension or a K2 plugin instead.

jim wrote: Could you possibly suggest an extension/k2 plugin that might do the trick? Ive looked but haven't found anything.
Many thanks in advance!


I can recommend RAXO Related K2 Items module which is specially designed to show related content for K2.

Description from the site:
RAXO Related K2 Items is a convenient module that automatically shows a list of K2 items related to the current entry, introducing your reader to the relevant content from around your K2 site. Be sure that every occasional visitor from Google gets enough interesting items to read and stay on your site forever.
RAXO Related K2 Items suggests various ways to find related content – by keywords, by tags, by author or by category. So you can be sure that every of your K2 items will get attention. This functional module is able to find the match for every single item to keep your reader engaged and increase your page views.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 10 months ago #155525 by Krikor Boghossian
Replied by Krikor Boghossian on topic Module to show related K2 items
Hello Alex,

If it can be triggered in category views then it will fit Jim.

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

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

More
8 years 10 months ago #155531 by jim
Replied by jim on topic Module to show related K2 items
@Krikor, many thanks, could you possibly clarify what you mean by triggered in category view, yes this is what i need I believe just simply the get related items function in the relevant file.

@Alex, many thanks, although that module is quite expensive at 25$ and im unsure/doubtful at this stage if it will provide the very simple count of related items for each item on category view

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

More
8 years 10 months ago #155532 by Alex B.
Replied by Alex B. on topic Module to show related K2 items
@jim
Hmmm, it looks like I got your task not correctly.
This module doesn't show up on category pages, only on K2 item pages.
So no, it won't fit you.

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

More
8 years 10 months ago - 8 years 10 months ago #155537 by jim
Replied by jim on topic Module to show related K2 items
@Alex no worries, thanks anyway, I thought so.
Is anoying how difficult such a simple requirement is proving to be.

@Krikor sorry to bother you again, but i dont suppose you know the file I need to copy the function get relateditems to do you?
Last edit: 8 years 10 months ago by jim.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 10 months ago #155538 by Krikor Boghossian
Replied by Krikor Boghossian on topic Module to show related K2 items
You have to copy the related functions from the items model like you did.

The you would have to copy the code from the item.php to the category_item.php.

Keep in mind that depending on the context $item and $this->item might be used.

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

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

More
8 years 10 months ago #155546 by jim
Replied by jim on topic Module to show related K2 items
Hi Krikor,

Thanks again for your reply/help much appreciated! :)

Sorry to bother you again, I was just wondering if you know where abouts I have to copy the related function to, im must be not putting it in the correct place/file, as im not having any luck with it here.

Many thanks if can possibly help!!!

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 10 months ago - 8 years 10 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 10 months ago by Mohamed Abdelaziz.

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

More
8 years 10 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 10 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 10 months ago - 8 years 10 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 10 months ago by jim.

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

More
8 years 10 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 10 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