Keyword

[SOLVED] Ordering K2 tags alphabetically

  • Pritesh Madlani
  • Pritesh Madlani's Avatar Topic Author
  • Offline
  • New Member
More
10 years 10 months 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
10 years 10 months 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
10 years 10 months 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
10 years 10 months 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
10 years 10 months 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.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
6 years 7 months ago - 6 years 7 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: 6 years 7 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
6 years 7 months ago #163200 by Krikor Boghossian
Replied by Krikor Boghossian on topic Ordering K2 tags alphabetically
This is useful Drazen.
Thank you :)

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Christophe BERTRAND
  • Christophe BERTRAND's Avatar
  • Offline
  • Senior Member
More
6 years 6 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
6 years 6 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
6 years 6 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

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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


Powered by Kunena Forum