Keyword

Show name of parent category in itemlist

  • Peter Haupt
  • Peter Haupt's Avatar Topic Author
  • Offline
  • New Member
More
14 years 9 months ago #76045 by Peter Haupt
Show name of parent category in itemlist was created by Peter Haupt
I'm trying to figure out how to display the name of the parent category in my views (itemlist, item).

I suppose I'll need to add some code somewhere comparing the "catid" out of the table "jos_k2_item" with the "id" out of the table "jos_k2_categories" and then I have to compare the "parent"-value with the "id" in the table "jos_k2_categories" to get the "name".
Here are my questions in which file would I have to insert the code and what would be the best way to solve this problem!

Thx

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

  • Peter Haupt
  • Peter Haupt's Avatar Topic Author
  • Offline
  • New Member
More
14 years 9 months ago #76046 by Peter Haupt
Replied by Peter Haupt on topic Show name of parent category in itemlist
Still trying to solve this problem. Can anybody help me, please?

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

  • Peter Haupt
  • Peter Haupt's Avatar Topic Author
  • Offline
  • New Member
More
14 years 9 months ago #76047 by Peter Haupt
Replied by Peter Haupt on topic Show name of parent category in itemlist
I'm trying to solve this problem with a code-snippet in generic.php:








Unfortunately it's not working they way I want it to. I know that isn't the best way to solve the problem. Can anybody help or give my an advice to solve this problem in a better way!

Thanks.

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

More
14 years 9 months ago #76048 by bkemler
Replied by bkemler on topic Show name of parent category in itemlist
generic.php only controls the tag view and the user view. This post about creating custom templates in k2 may be helpful... k2community.joomlaworks.gr/notes/Templating_in_K2

Peter Haupt said:I'm trying to solve this problem with a code-snippet in generic.php:







Unfortunately it's not working they way I want it to. I know that isn't the best way to solve the problem. Can anybody help or give my an advice to solve this problem in a better way!

Thanks.

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

More
13 years 11 months ago #76049 by Daniel Arnolf
Replied by Daniel Arnolf on topic Show name of parent category in itemlist
Please, anyone with any ideas, using the parent category name or id can save developing many subcategories overrides, at least in my case. I know the works around with inheritance etc, I just need a way to retrieve that parameter. I have png main category titles and I want to use a switch-case to change those titles and other stuff according to the parent category ID or name.
Thanks

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

More
13 years 11 months ago #76050 by Steinar A
Replied by Steinar A on topic Show name of parent category in itemlist
Hi all.

I'm fetching the name of the parent category for a sub-category by doing this in the view.html.php file:
$parentcategory = & JTable::getInstance('K2Category', 'Table');
$parentcategory->load($item->category->parent); //$item->category->parent is the id of the current (sub-)category
print_r($parentcategory->name);

Hope it helps someone :)

Regards,
Steinar

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

More
13 years 10 months ago #76051 by Daniel Arnolf
Replied by Daniel Arnolf on topic Show name of parent category in itemlist
Hi ,thank you very much, can you please be a bit more specific? I'm including it in /components/com_k2/views/item/view.html.php , below "$category->load($item->catid);" line ~575, then I try to output this variable in my template override item.php, with echo $this->item->parentcategory->name and other options, but not getting anywhere, I'll appreciate your help.

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

More
13 years 10 months ago #76052 by Steinar A
Replied by Steinar A on topic Show name of parent category in itemlist
Hi Daniel.
I just need to display it for SEO-reasons, so I use it on line ~240 like this:
$parentcategory = & JTable::getInstance('K2Category', 'Table');
$parentcategory->load($item->category->parent);
$document->setTitle($parentcategory->name . " " . $item->category->name . " " . $params->get('page_title'));

Regards,
Steinar


Daniel Arnolf said:Hi ,thank you very much, can you please be a bit more specific? I'm including it in /components/com_k2/views/item/view.html.php , below "$category->load($item->catid);" line ~575, then I try to output this variable in my template override item.php, with echo $this->item->parentcategory->name and other options, but not getting anywhere, I'll appreciate your help.

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

More
13 years 10 months ago #76053 by Daniel Arnolf
Replied by Daniel Arnolf on topic Show name of parent category in itemlist
Hi Steinar
I implemented your snippet successfully, to later understand that I can output the ID of the parent category without touching the core files: "echo $this->item->category->parent" , which is closer to what I was looking for running a switch and print graphic title according to parent category. Thank you very much indeed.

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

More
13 years 9 months ago #76054 by mchmaster
Replied by mchmaster on topic Show name of parent category in itemlist
Hi Daniel and Steiner,

 

I've been trying to do this exact thing except in my item listing in a k2_content module on my frontpage.

I tried using "echo $this->item->category->parent" as you said it worked for you and also "echo $item->category->parent". Obviously, since I'm posting here I wasn't able to get it to work.

 

Is there a way to get your method to work in a k2_content module displaying a list of recent articles?

I would really appreciate your help. Thanks.

 

Daniel Arnolf said:

Hi Steinar I implemented your snippet successfully, to later understand that I can output the ID of the parent category without touching the core files: "echo $this->item->category->parent" , which is closer to what I was looking for running a switch and print graphic title according to parent category. Thank you very much indeed.

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


Powered by Kunena Forum