Keyword

K2 php get category

More
8 years 2 months ago #151229 by fabio
K2 php get category was created by fabio
Hello to everyone. I'm new in this forum and i know quite well joomla CMS
In a custom site Joomla 3 + K2 i need to get category name and article name in details article by PHP Code (not breadcrumb) so i can output something like

You are here: Category Name -> Article Name

in my item.php

Thank you for help =)

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 2 months ago #151232 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 php get category
Remember to use overrides instead of editing the core files:
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

You can use this code as a starting point
You are here: <?php echo $this->item->category->name; ?> -> <?php echo $this->item->title; ?>

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

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

More
8 years 2 months ago #151261 by fabio
Replied by fabio on topic K2 php get category
Excellent! Exactly what i need. Can make also linkable the category?

Thank you

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 2 months ago #151275 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 php get category
Here you go:
You are here: <a href="<?php echo $this->item->category->link; ?>"><?php echo $this->item->category->name; ?></a> -> <?php echo $this->item->title; ?>

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

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

More
7 years 10 months ago #155006 by fabio
Replied by fabio on topic K2 php get category
Thank you very much.

I write here because i can't reply in this thread...

This is the link

The problem seems that in url category is missing..

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #155009 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 php get category
Hello, the URL is being generated from:
<?php echo $this->item->category->link; ?>

Keep in mind that depending on the context you might need to use $item instead of this $this->item.
<?php echo $item->category->link; ?>

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