Keyword

[SOLVED] Show parentcategory in Category-item.php

  • Benana
  • Benana's Avatar Topic Author
  • Offline
  • New Member
More
7 years 1 week ago - 7 years 1 week ago #102980 by Benana
Benana created the topic: [SOLVED] Show parentcategory in Category-item.php
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...
<?php echo $this->item->category->parent; ?> - <?php echo $this->item->category->name; ?>

Has someone a better idea.

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

More
7 years 1 week ago #102981 by Lefteris
Lefteris replied the 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; 
?>

IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

---
JoomlaWorks
www.joomlaworks.net/

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

  • Benana
  • Benana's Avatar Topic Author
  • Offline
  • New Member
More
7 years 1 week ago #102982 by Benana
Benana replied the topic: Re: Show parentcategory in Category-item.php
Thanks!
It works great!

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

More
7 years 1 week ago #102983 by Lefteris
Lefteris replied the topic: Re: Show parentcategory in Category-item.php
You are welcome.

IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

---
JoomlaWorks
www.joomlaworks.net/

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

More
6 years 8 months ago #102984 by Ardiansyah
Ardiansyah replied the 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
6 years 3 months ago #102985 by schug.trent
schug.trent replied the 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
6 years 3 months ago #102986 by schug.trent
schug.trent replied the topic: Re: Show parentcategory in Category-item.php
I got it. To bring the parent name in the category.php here is the code:
<?php 
$parent = JTable::getInstance('K2Category', 'Table');
$parent->load($this->category->parent);
echo $parent->name; 
?>

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

  • Alexander Ioannidis
  • Alexander Ioannidis's Avatar
  • Offline
  • Senior Member
More
4 years 11 months ago #102987 by Alexander Ioannidis
Alexander Ioannidis replied the 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.

Moderators: william white

Powered by Kunena Forum