Keyword

[SOLVED] Show parentcategory in Category-item.php

  • Benana
  • Benana's Avatar Topic Author
  • Offline
  • New Member
More
12 years 2 months ago - 12 years 2 months ago #102980 by Benana
Hi,
is it possible to show in category-item.php (override) the parent category of an item?

At the moment I only see the parent id...
Log in  or Create an account to join the conversation.

More
12 years 2 months ago #102981 by Lefteris
Replied by Lefteris on topic Re: Show parentcategory in Category-item.php
Hi. Try something like that:
<?php 
$parent = JTable::getInstance('K2Category', 'Table');
$parent->load($this->item->category->parent);
echo $parent->name; 
?>

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

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

  • Benana
  • Benana's Avatar Topic Author
  • Offline
  • New Member
More
12 years 2 months ago #102982 by Benana
Thanks!
It works great!

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

More
12 years 2 months ago #102983 by Lefteris
Replied by Lefteris on topic Re: Show parentcategory in Category-item.php
You are welcome.

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

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

More
11 years 10 months ago #102984 by Ardiansyah
Replied by Ardiansyah on topic Re: Show parentcategory in Category-item.php

Lefteris Kavadas wrote: Hi. Try something like that:

<?php 
$parent = JTable::getInstance('K2Category', 'Table');
$parent->load($this->item->category->parent);
echo $parent->name; 
?>


i using this in category.php v.2.6.2 notwoking

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

More
11 years 5 months ago #102985 by schug.trent
Replied by schug.trent on topic Re: Show parentcategory in Category-item.php
Has anyone figured this out for the newer version, K2 Version 2.6.6 ??

I want to display the image of the parent category in the category.php template. I tried the suggestion above, but it did not work.

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

More
11 years 5 months ago #102986 by schug.trent
Replied by schug.trent on topic Re: Show parentcategory in Category-item.php
I got it. To bring the parent name in the category.php here is the code:
Log in  or Create an account to join the conversation.

  • Alexander Ioannidis
  • Alexander Ioannidis's Avatar
  • Offline
  • Senior Member
More
10 years 1 month ago #102987 by Alexander Ioannidis
Replied by Alexander Ioannidis on topic Re: Show parentcategory in Category-item.php
Hey guys, thanks for this info. Just to add my bit, hoping it will be helpful to someone else:

I needed to get the ID of a category's parent category in the category.php file, so my code is
<?php
// Get the parent category name
$parent = JTable::getInstance('K2Category', 'Table');
$parent->load($this->category->parent);
$myparentid = $parent->id;
?>

And then to output the value
<?php echo $myparentid; ?>

Tested and working on 2.7.0 (development version)

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