Getting Category's custom fields in a blog view

Joomla Asked by Semaphore on September 5, 2021

I’m trying to get the custom fields value of a category in a blog view.
I have try the article item method but on the child item (supposed to be the current category item in the loop) :

JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');

then in the loop

<?php foreach ($this->children[$this->category->id] as $id => $child) : ?>
<?php foreach($child->jcfields as $jcfield)
      $child->jcFields[$jcfield->name] = $jcfield;

and then

<?php echo "test:".$child->jcFields['titre-discipline']->label; ?>

but i get nothing, no error, nothing. One the category actually get value in. THe custom show correctly in the category item view but not in this blog view.

Thanks for your help

One Answer

Load the fields with FieldsHelper::getFields(). This allows to access each field individually by its name.

<?php foreach(FieldsHelper::getFields('com_content.categories', $child) as $field) : ?>
    <?php $child->jcFields[$field->name] = $field; ?>
<?php endforeach; ?>
<?php echo "test:".$child->jcFields['titre-discipline']->label; ?>

If you just want to render the fields using the standard layout, use FieldsHelper::render() instead:

<?php echo FieldsHelper::render(
    array('context' => 'com_content.categories', 'item' => $child, 'fields' => FieldsHelper::getFields('com_content.categories', $child))
); ?>

Answered by Sharky on September 5, 2021

Add your own answers!

Related Questions

Generating a module instance from PHP

0  Asked on September 5, 2021 by ffrewin


Embed custom JS app in Joomla MVC

0  Asked on September 5, 2021 by miasto


Error when updating Gantry from 4.1.20 to 4.1.32

1  Asked on September 5, 2021 by norberto-gomes


Change user permissions programmatically on the fly

1  Asked on September 5, 2021 by aheavyobject


Akeeba backup update broke the site

2  Asked on September 5, 2021 by hamlet-kraskian


Proper way for autoloading in Joomla 4

1  Asked on September 5, 2021 by webchun


Menu Specifically For Super Users

1  Asked on September 5, 2021


Joomla PHP does not match host PHP

2  Asked on February 18, 2021


Controller Joomla – Output Class construct for color css style

1  Asked on February 5, 2021 by andrea-suriani


Joomla custom component – router not find alias

1  Asked on January 21, 2021 by lecraver


Joomla 3 call model function inside controller

3  Asked on December 28, 2020 by wbdevlop


Product url problem after updating VirtueMart

1  Asked on December 23, 2020 by kiasaty


Display intro image inside mod_breadcrumbs

0  Asked on November 11, 2020 by geoplous


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP