- Posts: 9
COMMUNITY FORUM
k2 related items in category_item.php
- jim
-
Topic Author
- Offline
- New Member
<?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
-
- Offline
- Platinum Member
- Posts: 15920
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.
- jim
-
Topic Author
- Offline
- New Member
- Posts: 9
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!
Please Log in or Create an account to join the conversation.
- Alex B.
-
- Offline
- New Member
- Posts: 8
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
-
- Offline
- Platinum Member
- Posts: 15920
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.
- jim
-
Topic Author
- Offline
- New Member
- Posts: 9
@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.
- Alex B.
-
- Offline
- New Member
- Posts: 8
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.
- jim
-
Topic Author
- Offline
- New Member
- Posts: 9
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?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
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.
- jim
-
Topic Author
- Offline
- New Member
- Posts: 9
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
-
- Offline
- Platinum Member
- Joomla Developer
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
Please Log in or Create an account to join the conversation.
- jim
-
Topic Author
- Offline
- New Member
- Posts: 9
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
-
- Offline
- Platinum Member
- Joomla Developer
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.
- jim
-
Topic Author
- Offline
- New Member
- Posts: 9
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!!! :)
Please Log in or Create an account to join the conversation.
- jim
-
Topic Author
- Offline
- New Member
- Posts: 9
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
-
- Offline
- Platinum Member
- Joomla Developer
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.