- Posts: 2
COMMUNITY FORUM
Similar Items by tags
- swordandstone
- Topic Author
- Offline
- New Member
Less
More
12 years 8 months ago - 12 years 8 months ago #61838
by swordandstone
Similar Items by tags was created by swordandstone
Hi everyone..
Sorry, i dont have perfect english, i will try to explain my problem now... I hope you'll understand, good luck!:)
In my website I use K2 component. I want that every single item shows similar items by tags. And yes, it shows. But it shows just last 5 items i added if there is at least one common tag. But i want that it firstly shows the items which has most common tags as the item the one being viewed. Is it possible? if so, how can I make it that way?
any solution?
Sorry, i dont have perfect english, i will try to explain my problem now... I hope you'll understand, good luck!:)
In my website I use K2 component. I want that every single item shows similar items by tags. And yes, it shows. But it shows just last 5 items i added if there is at least one common tag. But i want that it firstly shows the items which has most common tags as the item the one being viewed. Is it possible? if so, how can I make it that way?
any solution?
Please Log in or Create an account to join the conversation.
- swordandstone
- Topic Author
- Offline
- New Member
Less
More
- Posts: 2
12 years 8 months ago #61839
by swordandstone
Replied by swordandstone on topic Re: Similar Items by tags
I am talking about related articles... no one?
Please Log in or Create an account to join the conversation.
- Renea
- Offline
- New Member
Less
More
- Posts: 13
12 years 7 months ago #61840
by Renea
Replied by Renea on topic Re: Similar Items by tags
From the old forums:
Improve the ordering of your Related Items
- there will be listed items with AT LEAST 2 tags in common
- the list will be ordered by the number of tags in common
You should look in components/com_k2/models/itemlist.php for function:
in this function, look for code:and replace it with this code:
If you don't need to hide the items with only 1 tag in common just remove the "HAVING COUNT" row.
IF you think you need/like to show the number of tags in common in the template, like this example:
- the adventure og my angry dog [4 tags in common]
- the lying dog [3 tags in common]
etc.etc
You have to edit your template file [item.php] at row 439 [this file is placed in the component template dir or in you template dir if you use a custom template]:
Improve the ordering of your Related Items
- there will be listed items with AT LEAST 2 tags in common
- the list will be ordered by the number of tags in common
You should look in components/com_k2/models/itemlist.php for function:
function getRelatedItems($itemID, $tags, $limit) {
in this function, look for code:
$query = "SELECT DISTINCT itemID FROM #__k2_tags_xref WHERE tagID IN ({$sql}) AND itemID!={$itemID}";
$query = "SELECT i.*, c.alias as categoryalias, count(tags_xref.itemID) as quanti FROM #__k2_items as i".
" LEFT JOIN #__k2_categories c ON c.id = i.catid"." LEFT JOIN #__k2_tags_xref tags_xref ON tags_xref.itemID = i.id"." WHERE i.id != {$itemID}".
" AND i.published = 1"." AND ( i.publish_up = ".$db->Quote($nullDate)." OR i.publish_up <= ".$db->Quote($now)." )".
" AND ( i.publish_down = ".$db->Quote($nullDate)." OR i.publish_down >= ".$db->Quote($now)." )".
" AND i.access <= {$aid}"." AND i.trash = 0"." AND c.published = 1"." AND c.access <= {$aid}"." AND c.trash = 0"." AND (tags_xref.tagID) IN ({$sql})".
" GROUP BY i.id".
" HAVING COUNT(tags_xref.itemID)>1".
" ORDER BY quanti DESC";
If you don't need to hide the items with only 1 tag in common just remove the "HAVING COUNT" row.
IF you think you need/like to show the number of tags in common in the template, like this example:
- the adventure og my angry dog [4 tags in common]
- the lying dog [3 tags in common]
etc.etc
You have to edit your template file [item.php] at row 439 [this file is placed in the component template dir or in you template dir if you use a custom template]:
< a href="< ?php echo $item-> link ?> "> < ?php echo $item-> title; ?> < /a> < !--(< ?php echo $item-> quanti; ?> tags in common)
Please Log in or Create an account to join the conversation.
- Renea
- Offline
- New Member
Less
More
- Posts: 13
12 years 7 months ago #61841
by Renea
Replied by Renea on topic Re: Similar Items by tags
And I should note that this code hack was shared with K2 was on version 2.1 or 2.2.
I have 2.5 and its working just fine for me. I increased the number of tags from 1 to 3 in the HAVING COUNT line, which worked better for me.
Original post:
community.getk2.org/forum/topics/improve-the-ordering-of-your
I have 2.5 and its working just fine for me. I increased the number of tags from 1 to 3 in the HAVING COUNT line, which worked better for me.
Original post:
community.getk2.org/forum/topics/improve-the-ordering-of-your
Please Log in or Create an account to join the conversation.
- william white
- Offline
- Platinum Member
Less
More
- Posts: 3722
12 years 7 months ago #61842
by william white
Replied by william white on topic Re: Similar Items by tags
@renea Did you change the core or did you try to override the core by adding
YoursiteRoot/templates/YourTemplate/html/com_k2/models and place the file in there in some manner. I havent done this before but would be interested to know if it would work or not.
YoursiteRoot/templates/YourTemplate/html/com_k2/models and place the file in there in some manner. I havent done this before but would be interested to know if it would work or not.
Please Log in or Create an account to join the conversation.