- Posts: 17
COMMUNITY FORUM
Show name of parent category in itemlist
- Peter Haupt
-
Topic Author
- Offline
- New Member
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
-
Topic Author
- Offline
- New Member
- Posts: 17
Please Log in or Create an account to join the conversation.
- Peter Haupt
-
Topic Author
- Offline
- New Member
- Posts: 17
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.
- bkemler
-
- Offline
- Premium Member
- Posts: 87
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.
- Daniel Arnolf
-
- Offline
- New Member
- Posts: 6
Thanks
Please Log in or Create an account to join the conversation.
- Steinar A
-
- Offline
- New Member
- Posts: 4
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.
- Daniel Arnolf
-
- Offline
- New Member
- Posts: 6
Please Log in or Create an account to join the conversation.
- Steinar A
-
- Offline
- New Member
- Posts: 4
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.
- Daniel Arnolf
-
- Offline
- New Member
- Posts: 6
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.
- mchmaster
-
- Offline
- New Member
- Posts: 12
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.
- Steinar A
-
- Offline
- New Member
- Posts: 4
This is not a nice hack, but you can "reload" the category by:
(in modules/mod_k2_content/tmpl/Default/default.php (or make your own template)).
$category = & JTable::getInstance('K2Category', 'Table');$category->load($item->catid);
Then you can access the parent-attribute by:
echo $category->parent;
And if you also need the name of the parent category:
$parentcategory = & JTable::getInstance('K2Category', 'Table'); $parentcategory->load($category->parent);
echo $parentcategory->name;
I have no idea how to make K2 content displaying a list of recent articles tho...
Steinar
Please Log in or Create an account to join the conversation.
- mchmaster
-
- Offline
- New Member
- Posts: 12
My hope is to create a recent article listing with articles from different categories. Each article's parent category will be shown next to the article title. If I can call each parent category, then I can make individual styles as well.
If you go to www.blessedteensacademy.com and look at the module in the middle titled "New Content", you'll see where I'm trying to apply this.
Any ideas? Thank you so much for your time! Steinar A said:
Seems like the $item in the K2 module doesn't contain the parent-attribute.
This is not a nice hack, but you can "reload" the category by:
(in modules/mod_k2_content/tmpl/Default/default.php (or make your own template)).
$category = & JTable::getInstance('K2Category', 'Table');$category->load($item->catid);
Then you can access the parent-attribute by:
echo $category->parent;
And if you also need the name of the parent category:
$parentcategory = & JTable::getInstance('K2Category', 'Table'); $parentcategory->load($category->parent);
echo $parentcategory->name;
I have no idea how to make K2 content displaying a list of recent articles tho...
Steinar
Please Log in or Create an account to join the conversation.
- mchmaster
-
- Offline
- New Member
- Posts: 12
Please Log in or Create an account to join the conversation.
- Duane Arnett
-
- Offline
- New Member
- Posts: 1
I dont see anyway of doing this?
Please Log in or Create an account to join the conversation.
- petzov
-
- Offline
- New Member
- Posts: 1
This worked for me. Put this in index.php.
$database = &JFactory::getDBO();
$itemid= JRequest::getVar('id',0);
$sql = "SELECT name FROM jos_k2_items t1, jos_k2_categories t2 WHERE t1.catid = t2.id and t1.id='".$itemid."'" ; $database->setQuery( $sql ); $row=$database->loadResult(); echo $row;
It is an old post, but somebody may need it in the future.
Please Log in or Create an account to join the conversation.