Help Center

Powered by Minitek FAQ Book
Loading...

How to add a fields Featured

DB
Dejan BojovicPosted 1 year ago

How to add a fields to article_slider_1?

I try:

 

<?php
if (isset($this->item->jcfields['8']->value) && !empty($this->item->jcfields['8']->value)) : ?>
<div class="field-objekat-popust">    
<div class="label-objekat-popust"><?php echo $this->item->jcfields[8]->label; ?></div>
<?php echo $this->item->jcfields[8]->value; ?></div>
<?php  endif; ?>

but without success.

Loading...
0
#3636

2 answers

M
MinitekPosted 1 year agoEdited 1 year agoModerator

Try the following (inside the $items for loop):

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

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

Now, if you want to display all fields:

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

If you want to display a specific custom field:

// 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>
DB
Dejan BojovicPosted 1 year ago

Great

Thanks