Keyword

How to get tag name in tag itemlist?

  • Roman Lipatov
  • Roman Lipatov's Avatar Topic Author
  • Offline
  • Premium Member
More
9 years 3 weeks ago #153527 by Roman Lipatov
How to get tag name in tag itemlist? was created by Roman Lipatov
Hi!

I need to modificate meta titles and descriptions on tags pages.
http://mysites/news/tags/tag1

But I want to make it only using templates overrides.

How I can get tag name (variable) in template file /components/com_k2/templates/default/tag.php

Thanks.

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

  • JoomlaWorks Support Team
  • JoomlaWorks Support Team's Avatar
  • Offline
  • Elite Member
More
9 years 3 weeks ago #153539 by JoomlaWorks Support Team
Replied by JoomlaWorks Support Team on topic How to get tag name in tag itemlist?
Hi,
You can create a K2 tag menu item and add the Meta Description and Keywords at the menu metadata options.

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

  • Roman Lipatov
  • Roman Lipatov's Avatar Topic Author
  • Offline
  • Premium Member
More
9 years 3 weeks ago #153542 by Roman Lipatov
Replied by Roman Lipatov on topic How to get tag name in tag itemlist?

Teo wrote: Hi,
You can create a K2 tag menu item and add the Meta Description and Keywords at the menu metadata options.


Yes, but I still need get tag name (variable) in template, because I need to add descritption for this tag page.



My idea is to make tags pages same as categories pages.
Users should not see the difference between these pages.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 3 weeks ago #153553 by Krikor Boghossian
Replied by Krikor Boghossian on topic How to get tag name in tag itemlist?
The URL pattern you see here, was created from a menu item.
Create a blank K2 categories menu item (leave the category selection empty) and call it eg: show or content, this will create the URL pattern you see there.

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

  • Roman Lipatov
  • Roman Lipatov's Avatar Topic Author
  • Offline
  • Premium Member
More
9 years 3 weeks ago #153555 by Roman Lipatov
Replied by Roman Lipatov on topic How to get tag name in tag itemlist?
You understood me wrong.

I need to get Tag name in tags template /components/com_k2/templates/default/tag.php

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

  • JoomlaWorks Support Team
  • JoomlaWorks Support Team's Avatar
  • Offline
  • Elite Member
More
9 years 3 weeks ago - 9 years 3 weeks ago #153572 by JoomlaWorks Support Team
Replied by JoomlaWorks Support Team on topic How to get tag name in tag itemlist?
You can fetch the tag name with php. Try this code snippet at your tag.php template
$tag = JRequest::getString('tag');
echo $tag;
Last edit: 9 years 3 weeks ago by JoomlaWorks Support Team.

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

  • Roman Lipatov
  • Roman Lipatov's Avatar Topic Author
  • Offline
  • Premium Member
More
9 years 3 weeks ago #153577 by Roman Lipatov
Replied by Roman Lipatov on topic How to get tag name in tag itemlist?
Thanks Teo!
It works perfect.

Tell me please, how I can get other data from tags table, for example tag id?

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

  • JoomlaWorks Support Team
  • JoomlaWorks Support Team's Avatar
  • Offline
  • Elite Member
More
9 years 3 weeks ago #153629 by JoomlaWorks Support Team
Replied by JoomlaWorks Support Team on topic How to get tag name in tag itemlist?
You must again use PHP and query the database table macb_k2_tags in order to get the data you want.

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

  • Roman Lipatov
  • Roman Lipatov's Avatar Topic Author
  • Offline
  • Premium Member
More
9 years 3 weeks ago - 9 years 3 weeks ago #153650 by Roman Lipatov
Replied by Roman Lipatov on topic How to get tag name in tag itemlist?
Yes, I tried, but it does not work...
$id = JRequest::getString('id');
echo $id;
Last edit: 9 years 3 weeks ago by Roman Lipatov.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 3 weeks ago #153670 by Krikor Boghossian
Replied by Krikor Boghossian on topic How to get tag name in tag itemlist?
This will not work, you need an SQL query in order to retrieve further data.

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

  • Roman Lipatov
  • Roman Lipatov's Avatar Topic Author
  • Offline
  • Premium Member
More
9 years 3 weeks ago #153671 by Roman Lipatov
Replied by Roman Lipatov on topic How to get tag name in tag itemlist?
Why not? It looks same as with $tag = JRequest::getString('tag'); example...

How looks SQL query in this case?
Thanks.

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

  • Roman Lipatov
  • Roman Lipatov's Avatar Topic Author
  • Offline
  • Premium Member
More
9 years 2 weeks ago #153735 by Roman Lipatov
Replied by Roman Lipatov on topic How to get tag name in tag itemlist?
Can get it :(

I trying this code to get tag ID, but it does not work...
<?php
		$tag = JRequest::getString('tag'); 
		echo $tag;
		
		$dbc=&JFactory::getDBO();
		$sql="select id from k2_tags where name='".$tag."';";
		$dbc->setQuery($sql);
		echo $dbc;
?>

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

  • Roman Lipatov
  • Roman Lipatov's Avatar Topic Author
  • Offline
  • Premium Member
More
9 years 2 weeks ago #153736 by Roman Lipatov
Replied by Roman Lipatov on topic How to get tag name in tag itemlist?
OK, it seems I got it.
But I need your mind about this code.

I think it is too big to just get the ID value...
<?php
		$tag = JRequest::getString('tag'); 
		echo $tag;
		
		$db = JFactory::getDBO();
		$query = "SELECT * from #__k2_tags where name='".$tag."'";
		$db->setQuery($query);
		$result = $db->loadObjectList();
		foreach($result as $key=>$value){
		echo $value->id;
										}
?>

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 2 weeks ago #153791 by Krikor Boghossian
Replied by Krikor Boghossian on topic How to get tag name in tag itemlist?
Hello Roman,

I will need some context, the query appears indeed correct.
Where did you paste it? In the top of the tag.php file or inside the loop?

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

  • Roman Lipatov
  • Roman Lipatov's Avatar Topic Author
  • Offline
  • Premium Member
More
9 years 2 weeks ago #153803 by Roman Lipatov
Replied by Roman Lipatov on topic How to get tag name in tag itemlist?
Hi Krikor,
I paste this code at the top.



My idea is to add new columns in k2_tags mysql table - description, meta description, meta title, icon.

So, I will be able to build tags pages, that will looks same as categories.



I think, that this feature should be a part of K2...



But right now I trying to make it with hack, and I not sure, that code above is correct, and it will not work slow (I'm not programmer).

Thanks.

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


Powered by Kunena Forum