Forked from alexandreelise/add-custom-fields-to-core-modules-j3x.php
Created
April 12, 2022 12:51
-
-
Save hamidionline/71ae174a685c859bae1f7c01e68c6e7d to your computer and use it in GitHub Desktop.
Add custom fields to core modules in Joomla! 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| defined('_JEXEC') or die; | |
| ?> | |
| <div class="latestnews"> | |
| <ul class="list-group list-group-flush"> | |
| <?php foreach ($list as $item) : $image = json_decode($item->images); ?> | |
| <?php | |
| // most important part | |
| // context: | |
| // for articles: com_content.article | |
| // for users: com_users.user | |
| // etc... | |
| $jcfields = FieldsHelper::getFields('com_content.article', $item, true); | |
| // bonus: custom fields by name | |
| // usage: $fields_by_name['name-of-field']->value | |
| $fields_by_name = \Joomla\Utilities\ArrayHelper::pivot($jcfields, 'name'); | |
| ?> | |
| <li itemscope itemtype="https://schema.org/Article" class="list-group-item px-0" style="background-color:<?php echo $fields_by_name['article-favourite-color']->value; ?>"> | |
| <?php if($image->image_intro != "") : ?> | |
| <a class="article-media" href="<?php echo $item->link; ?>" itemprop="url"> | |
| <img class="card-img-top pb-2" src="<?php echo JURI::root().$image->image_intro; ?>" alt="<?php echo htmlspecialchars($image->image_fulltext_alt); ?>"> | |
| </a> | |
| <?php endif; ?> | |
| <a class="article-title" href="<?php echo $item->link; ?>" itemprop="url"> | |
| <span itemprop="name"> | |
| <?php echo $item->title; ?> | |
| </span> | |
| </a> | |
| </li> | |
| <?php endforeach; ?> | |
| </ul> | |
| </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment