- Posts: 52
COMMUNITY FORUM
Need to show a related item from a different category
- Geoffrey Mack
-
Topic Author
- Offline
- Senior Member
Less
More
14 years 5 months ago #91207
by Geoffrey Mack
Need to show a related item from a different category was created by Geoffrey Mack
I tried to create a K2 Module to do this, but was surprised to see that I could not do it. I want to show Related Items by Tag, from a different category.
So for example, if I am looking at a page in my audio/visual receivers category with a dolby 7.1 receiver, I'd like to be able to show dolby 7.1 speaker systems which happen to be in a different category called speaker systems.
I've approached this from several angles:
* Creating a K2 Items module allows me to retrieve items from categories, but not by tag. So, using my example, it would show all speaker systems and not just the 7.1 speakers.
* Under Categories, changing the item view to show related items by tag just shows related items from the same category, so it would just show me related receivers and not speaker systems.
* Using the Extra Fields feature doesn't appear to let me selectively link to items (in a way that would be easy for my site owners to manage.)
Does anybody see a way around this?
Thanks
So for example, if I am looking at a page in my audio/visual receivers category with a dolby 7.1 receiver, I'd like to be able to show dolby 7.1 speaker systems which happen to be in a different category called speaker systems.
I've approached this from several angles:
* Creating a K2 Items module allows me to retrieve items from categories, but not by tag. So, using my example, it would show all speaker systems and not just the 7.1 speakers.
* Under Categories, changing the item view to show related items by tag just shows related items from the same category, so it would just show me related receivers and not speaker systems.
* Using the Extra Fields feature doesn't appear to let me selectively link to items (in a way that would be easy for my site owners to manage.)
Does anybody see a way around this?
Thanks
Please Log in or Create an account to join the conversation.
- Geoffrey Mack
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 52
14 years 4 months ago #91208
by Geoffrey Mack
Replied by Geoffrey Mack on topic Need to show a related item from a different category
Anybody have any thoughts on how to accomplish this? I need to show related items by tag, but the items should not be from the category that the user is on.
Need help.
Need help.
Please Log in or Create an account to join the conversation.
- Pixeden
-
- Offline
- New Member
Less
More
- Posts: 6
13 years 10 months ago #91209
by Pixeden
Replied by Pixeden on topic Need to show a related item from a different category
Hi all,
You need to edit item.php (on your custom template will be better).
Now in the
<!-- Related items by tag --> <div class="itemRelated">
Just after the loop:
<?php foreach($this->relatedItems as $key=>$item): ?>
<!--First we find the id of the category of the item diplayed and we put it on a variable -->
<?php $currentid = $this->item->category->id; ?>
<!--Now if the category id of the related item is the same than the current category we don't display the tag -->
<?php if( $item->catid == $currentid) : ?>
<!--display nothing -->
<?php else:?>
<!--we display the tag -->
<li class="<?php echo ($key%2) ? "odd" : "even"; ?>"> <a href="<?php echo $item->link ?>"><?php echo $item->title; ?></a> </li>
<!--we close the if statement --><?php endif; ?>
<?php endforeach; ?> </ul>
I didn't test this code, but it should work.
Any questions don't hesitate!
You need to edit item.php (on your custom template will be better).
Now in the
<!-- Related items by tag --> <div class="itemRelated">
Just after the loop:
<?php foreach($this->relatedItems as $key=>$item): ?>
<!--First we find the id of the category of the item diplayed and we put it on a variable -->
<?php $currentid = $this->item->category->id; ?>
<!--Now if the category id of the related item is the same than the current category we don't display the tag -->
<?php if( $item->catid == $currentid) : ?>
<!--display nothing -->
<?php else:?>
<!--we display the tag -->
<li class="<?php echo ($key%2) ? "odd" : "even"; ?>"> <a href="<?php echo $item->link ?>"><?php echo $item->title; ?></a> </li>
<!--we close the if statement --><?php endif; ?>
<?php endforeach; ?> </ul>
I didn't test this code, but it should work.
Any questions don't hesitate!
Please Log in or Create an account to join the conversation.