Keyword

Show name of parent category in itemlist

More
13 years 9 months ago #76055 by Steinar A
Replied by Steinar A on topic Show name of parent category in itemlist
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.

More
13 years 9 months ago #76056 by mchmaster
Replied by mchmaster on topic Show name of parent category in itemlist
Thank you so much for your quick reply. I tried to apply those snippets to my module template, but all I got was a white screen with the first article title and nothing else, no error report either. Could this have to do with the fact that I'm calling multiple articles at once instead of just viewing a single article?

 

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.

More
13 years 7 months ago #76057 by mchmaster
Replied by mchmaster on topic Show name of parent category in itemlist
If anyone can help with this, I'm stuck!!!!

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

More
13 years 4 months ago #76058 by Duane Arnett
Replied by Duane Arnett on topic Show name of parent category in itemlist
Is there a way to get the category parent in index.php?  

I dont see anyway of doing this?

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

More
13 years 1 month ago #76059 by petzov
Replied by petzov on topic Show name of parent category in itemlist
Hi guys,

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.


Powered by Kunena Forum