Keyword

[SOLVED] Ordering K2 tags alphabetically

  • Pritesh Madlani
  • Pritesh Madlani's Avatar Topic Author
  • Offline
  • New Member
More
12 years 3 weeks ago #112618 by Pritesh Madlani
Ordering K2 tags alphabetically was created by Pritesh Madlani
Hi,

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
  • Pritesh Madlani's Avatar Topic Author
  • Offline
  • New Member
More
12 years 2 weeks ago #112619 by Pritesh Madlani
Replied by Pritesh Madlani on topic Re: Ordering K2 tags alphabetically
Hi,

Any ideas anyone?

Thanks in advance.

Prit

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

More
12 years 2 weeks ago #112620 by Sylvias
Replied by Sylvias on topic Re: Ordering K2 tags alphabetically
Bump! :kiss:

"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
  • Pritesh Madlani's Avatar Topic Author
  • Offline
  • New Member
More
12 years 1 week ago #112621 by Pritesh Madlani
Replied by Pritesh Madlani on topic Re: Ordering K2 tags alphabetically
Anyone? :unsure:

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
12 years 1 week ago #112622 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Ordering K2 tags alphabetically
Hello,

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.

More
7 years 9 months ago - 7 years 9 months ago #163189 by razen
Replied by razen on topic Ordering K2 tags alphabetically
I hope this wont count as gravedigging - I just want to help persons with that problem since I had it, too.

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 ...
Last edit: 7 years 9 months ago by razen.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 9 months ago #163200 by Krikor Boghossian
Replied by Krikor Boghossian on topic Ordering K2 tags alphabetically
This is useful Drazen.
Thank you :)

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

  • Christophe BERTRAND
  • Christophe BERTRAND's Avatar
  • Offline
  • Senior Member
More
7 years 7 months ago #164334 by Christophe BERTRAND
Replied by Christophe BERTRAND on topic Ordering K2 tags alphabetically
Hi
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.

More
7 years 7 months ago #164335 by razen
Replied by razen on topic Ordering K2 tags alphabetically
I run on k2 2.8 and the hint still works.

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 7 months ago #164349 by Krikor Boghossian
Replied by Krikor Boghossian on topic Ordering K2 tags alphabetically
More on overrides can be found here:
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.

More
7 years 6 months ago #164910 by Catherine Mollet
Replied by Catherine Mollet on topic Ordering K2 tags alphabetically
Thanks a lot Razen! Saved my life ;-)

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

  • Christophe BERTRAND
  • Christophe BERTRAND's Avatar
  • Offline
  • Senior Member
More
7 years 6 months ago #165002 by Christophe BERTRAND
Replied by Christophe BERTRAND on topic Ordering K2 tags alphabetically
Hi,
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.

More
7 years 6 months ago #165009 by razen
Replied by razen on topic Ordering K2 tags alphabetically
Where do you want to modify the sorting of the tags?

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
  • Christophe BERTRAND's Avatar
  • Offline
  • Senior Member
More
7 years 6 months ago - 7 years 6 months ago #165014 by Christophe BERTRAND
Replied by Christophe BERTRAND on topic Ordering K2 tags alphabetically
Hi Razen,
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
Last edit: 7 years 6 months ago by Christophe BERTRAND.

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

More
7 years 6 months ago #165015 by razen
Replied by razen on topic Ordering K2 tags alphabetically
I never looked into this, but I'm quite sure the file for this is in administrator/components/com_k2 or so.

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 6 months ago #165126 by Krikor Boghossian
Replied by Krikor Boghossian on topic Ordering K2 tags alphabetically
It depends on which tags you want to sort.
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.


Powered by Kunena Forum