Help Center

Powered by Minitek FAQ Book
Loading...

Is it possible to display Joomla articles custom fields Featured

PG
Patrick GaulinPosted 2 years agoEdited 2 years 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...
1
#3380

1 answer

M
MinitekPosted 2 years 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>