- Posts: 3
COMMUNITY FORUM
[SOLVED] Ordering K2 tags alphabetically
- Pritesh Madlani
-
Topic Author
- Offline
- New Member
Is it possible to order the K2 tags for items alphabetically in category layout and item view layout?
Many thanks
Prit
Please Log in or Create an account to join the conversation.
- Pritesh Madlani
-
Topic Author
- Offline
- New Member
- Posts: 3
Any ideas anyone?
Thanks in advance.
Prit
Please Log in or Create an account to join the conversation.
- Sylvias
-
- Offline
- New Member
- Posts: 10
"In solidarity, unity and support; we the K2 Community, will stand together and committed; to growing, improving and maximizing the amazing the system K2 truly is!" -- Sylvia
Please Log in or Create an account to join the conversation.
- Pritesh Madlani
-
Topic Author
- Offline
- New Member
- Posts: 3
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
The tags are rendered by default in the order the user enters them.
You need to override the appropriate template files (ie. category_item.php and item.php) and sort the array of the tags using PHP.
Please Log in or Create an account to join the conversation.
- razen
-
- Offline
- Senior Member
- Posts: 46
This here is the original code in the item.php:
<?php foreach ($this->item->tags as $tag): ?>
<a href="<?php echo $tag->link; ?>"><?php echo $tag->name; ?></a>,
<?php endforeach; ?>
Replace it with this:
<?php
foreach($this->item->tags as $key=>$value )
{
$sort[$value->name]=array($value->name,$value->link);
}
ksort($sort) ;
foreach ($sort as $tag) {
echo '<a href="' . $tag[1] . '">' . $tag[0] . ',</a> ';
}
?>
It works for me and I hope I could help some people ...
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Thank you :)
Please Log in or Create an account to join the conversation.
- Christophe BERTRAND
-
- Offline
- Senior Member
- Posts: 46
I just updated to K 2.8
For the ordering by Tags name alphabetically, before I used this hint :
in administrator/components/com_k2/models/item.php line 757 :
if (!is_null($itemID))
$query .= " WHERE tags.id NOT IN (SELECT tagID FROM #__k2_tags_xref WHERE itemID={$itemID})";
$db->setQuery($query);
I used to change it to:
if (!is_null($itemID))
$query .= " WHERE tags.id NOT IN (SELECT tagID FROM #__k2_tags_xref WHERE itemID={$itemID}) ORDER BY tags.name";
$db->setQuery($query);
added: ORDER BY tags.name
But this doesn't seem to work anymore.
Could you please tell me where is the "item.php" file I need to change and to put the changes proposed by Razen ?
Or if there is another trick to order the tags alphabetically ?
Thanks
Please Log in or Create an account to join the conversation.
- razen
-
- Offline
- Senior Member
- Posts: 46
The original file is here if I'm right:
/components/com_k2/templates/default/item.php
But I highly recommend to copy it to your joomla template if you update the file:
/templates/[YourTemplate]/html/com_k2/default/item.php
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Although if you want to order the tag LISTINGS, then you need to edit K2's options -> jmp.sh/tsT5RTB
Please Log in or Create an account to join the conversation.
- Catherine Mollet
-
- Offline
- New Member
- Posts: 8
Please Log in or Create an account to join the conversation.
- Christophe BERTRAND
-
- Offline
- Senior Member
- Posts: 46
Sorry to insist on this post.
I understand Razen and Catherine made it work, but I can't.
I am probably missing something, but whatever item.php file I modify (in template/html/... or even in administrator/component/...) with Razen's method, the tags when I add (or edit) a k2 item never order in alphabetical order !
Could you please help again ?
Thanks
Please Log in or Create an account to join the conversation.
- razen
-
- Offline
- Senior Member
- Posts: 46
I would recommend that you first identify the right template with an X somwhere in the file temporary untill you found it - cause youÄre simply in the wrong file yet (as far as I can see).
For the frontend, there should be a file in the template you use - if it doesnt exist, create it:
templates/[yourtemplate]/com_k2/default/item.php
Please Log in or Create an account to join the conversation.
- Christophe BERTRAND
-
- Offline
- Senior Member
- Posts: 46
Thanks for your response.
I will try, but so far I changed it where yoy say.
Where I want to sort the Tags is when I create (or edit) a K2 item in the back-end (or front-end) in the left box tags (I think by default thy are sorted out by # of IDs).
For this, should the changes be in templates/[yourtemplate]/com_k2/default/item.php ? or in an itemform.php ?
Thanks
Christophe
Please Log in or Create an account to join the conversation.
- razen
-
- Offline
- Senior Member
- Posts: 46
And I also think that my method wont work for those backend-tags, cause those are no simple links
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
The code here is for the item.php file which should be overriden.
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Please Log in or Create an account to join the conversation.