Show parent root category of category field (code included)

More
11 years 8 months ago #42947 by jrodgar
Hi!

Would like to share this. I used it on the template to show the parent root of a subcategory. It´s implemented on the template, but I think it would be better as part of the "category" field. It´s something like this:
Code:
<?php if ($field->name == "categories") : ?> <?php preg_match_all("/fc_category_(\d+)/",$field->display, $matches); $categoriesID = $matches[1]; //Get Category Parent Category $categoriesModel = JCategories::getInstance('content'); $parentCategories = ""; foreach ($categoriesID as $categoryId) { $category = $categoriesModel->get($categoryId); $parent = $category; while ($parent->getParent()->id != "root") { $parent = $parent->getParent(); } if($parent->id != "root" && $parent->id != $category->id){ $parentCategories .= print_r($categoriesModel->get($parent->id)->title,true)." "; } } $parentCategories = $parentCategories ? $parentCategories."- " : ""; ?> <?php endif; ?> <div class="flexi value field_<?php echo $field->name; ?>"><?php echo $parentCategories.$field->display; ?></div>

Unless otherwise indicated:
Joomla 3.8.1
Flexicontent 3.2.1.7

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

More
11 years 8 months ago #42952 by micker
thanks !

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

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

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.344 seconds
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline
Save