Rendering custom fields in module latest news
Moderator: General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
-
- Joomla! Fledgling
- Posts: 4
- Joined: Sat Apr 14, 2018 12:06 am
Rendering custom fields in module latest news
Dear,
I've created some custom fields to integrate into a certain category of articles. These articles are displayed in a customized module of latest news. I would like to display these custom fields in the module, but I can not. Could someone help me in this matter
Thank you!
I've created some custom fields to integrate into a certain category of articles. These articles are displayed in a customized module of latest news. I would like to display these custom fields in the module, but I can not. Could someone help me in this matter
Thank you!
- effrit
- Joomla! Guru
- Posts: 846
- Joined: Sun Nov 12, 2017 2:21 pm
- Location: middle of Russia
- Contact:
Re: Rendering custom fields in module latest news
hi
you must make database request.
you can do it by php or using Joomla classes but it's still DB request...
for single article with id = $id
by framework
you must make database request.
you can do it by php or using Joomla classes but it's still DB request...
for single article with id = $id
Code: Select all
$db = JFactory::getDbo();
$query = 'select * from #__fields_values where item_id = "'.$id.'"';
$db->setQuery($query);
$fields = $db->loadObjectList();
by framework
Code: Select all
$item->jcfields = FieldsHelper::getFields('com_content.article', $item, true);
$fields = [];
foreach($item->jcfields as $jcfield)
{
$fields[$jcfield->name] = $jcfield;
}
var_dump ($fields);
http://effrit.com/joomla | clean Word/Excel tables: http://r91228pz.bget.ru
-
- Joomla! Apprentice
- Posts: 8
- Joined: Tue Apr 10, 2018 3:09 am
Re: Rendering custom fields in module latest news
Ok, but how do we do it? Do we need to create a module?effrit wrote:hi
you must make database request.
you can do it by php or using Joomla classes but it's still DB request...
for single article with id = $id
Code: Select all
$db = JFactory::getDbo(); $query = 'select * from #__fields_values where item_id = "'.$id.'"'; $db->setQuery($query); $fields = $db->loadObjectList();
by frameworkCode: Select all
$item->jcfields = FieldsHelper::getFields('com_content.article', $item, true); $fields = []; foreach($item->jcfields as $jcfield) { $fields[$jcfield->name] = $jcfield; } var_dump ($fields);
- effrit
- Joomla! Guru
- Posts: 846
- Joined: Sun Nov 12, 2017 2:21 pm
- Location: middle of Russia
- Contact:
Re: Rendering custom fields in module latest news
the topic is about "Rendering custom fields in module latest news" so you must create new template for this module (or override in template for it)and paste first or second example code it it in loop there items are shown
http://effrit.com/joomla | clean Word/Excel tables: http://r91228pz.bget.ru
-
- Joomla! Fledgling
- Posts: 4
- Joined: Sat Apr 14, 2018 12:06 am
Re: Rendering custom fields in module latest news
effrit wrote:hi
you must make database request.
you can do it by php or using Joomla classes but it's still DB request...
for single article with id = $id
Code: Select all
$db = JFactory::getDbo(); $query = 'select * from #__fields_values where item_id = "'.$id.'"'; $db->setQuery($query); $fields = $db->loadObjectList();
by frameworkCode: Select all
$item->jcfields = FieldsHelper::getFields('com_content.article', $item, true); $fields = []; foreach($item->jcfields as $jcfield) { $fields[$jcfield->name] = $jcfield; } var_dump ($fields);
OK! More then I have the following situation: Each article will have a different custom field value. How to redenricionar the respective field in the module?
Code: Select all
<ul class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) : ?>
<li itemscope itemtype="https://schema.org/Article">
<a href="<?php echo $item->link; ?>" itemprop="url">
<span itemprop="name">
<?php echo $item->title; ?>
</span>
</a>
</li>
<?php endforeach; ?>
</ul>
- effrit
- Joomla! Guru
- Posts: 846
- Joined: Sun Nov 12, 2017 2:21 pm
- Location: middle of Russia
- Contact:
Re: Rendering custom fields in module latest news
paste in any place inside foreach.
after <li itemscope itemtype="https://schema.org/Article">, for example.
after <li itemscope itemtype="https://schema.org/Article">, for example.
Code: Select all
<?php
$id=$item->id;
$db = JFactory::getDbo();
$query = 'select * from #__fields_values where item_id = "'.$id.'"';
$db->setQuery($query);
$fields = $db->loadObjectList();
foreach ($fields as $field) {
if ($field->field_id == 2) { // 2 - id of your custom field
echo $field->value;
}
}
?>
http://effrit.com/joomla | clean Word/Excel tables: http://r91228pz.bget.ru
-
- Joomla! Enthusiast
- Posts: 170
- Joined: Wed Dec 03, 2008 9:02 am
Re: Rendering custom fields in module latest news
Hi,
Above code renders the CF value, how can I show also the custom field label?
Thank you.
Above code renders the CF value, how can I show also the custom field label?
Thank you.