Help Center

Powered by Minitek FAQ Book

Is it possible to display Joomla articles custom fields Featured

PG
Patrick GaulinPosted 7 months agoEdited 7 months ago

Hi,

I need to display 3 custom fields that I added to my Joomla articles. Is there a way to make them appear in the Detail Box?

Loading...
0
#3380

1 answer

M
MinitekPosted 7 months agoModerator

Hi there,

You must customize the template files in order to display custom fields. You can use the following code:

$item->jcfields = Joomla\Component\Fields\Administrator\Helper\FieldsHelper::getFields('com_content.article', $item, true);
$fields = [];

foreach ($item->jcfields as $jcfield)
{
  $fields[$jcfield->name] = $jcfield;
}

// Display all custom fields
foreach ($fields as $field) 
{ 
  ?><p><?php echo $field->title; ?></p>
  <p><?php echo $field->value; ?></p><?php 
}

// Display a specific custom field
<p><?php echo $fields['enter-field-alias-here']->title; ?></p>
<p><?php echo $fields['enter-field-alias-here']->value; ?></p>