0

I've already created a custom field called "part-no", and I want to show the "part-no" that exist in all articles in the same category. But now it only show the "part-no" from last article, how to show it from all articles? I don't want to use table.

part-no = NO1 in article1,
part-no = NO2 in article2,
part-no = NO3 in article3,

Now it only shows N03

I want to show: N01, N02, NO3

I overided default_articles.php like below:

<?php
defined ('_JEXEC') or die();
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
use Joomla\CMS\Router\Route;

    // Create some shortcuts.
$params    = &$this->item->params;

// Check for at least one editable article
$isEditable = false;

if (!empty($this->items))
{
    foreach ($this->items as $article)
    {
        if ($article->params->get('access-edit'))
        {
            $isEditable = true;

        }
    }
}
?>

<?php if (!empty($this->items)) : ?>
<?php foreach($article->jcfields as $jcfield){
    $article->jcFields[$jcfield->name] = $jcfield;
}
?>

<?php echo $article->jcFields['part-no']->value; ?>
<?php endif; ?>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3
  • <?php echo $article->jcFields['part-no']->value; ?> is only called once (after the loop is finished iterating) -- so you will only have access to the final iteration's data. Also, I don't know that this check makes any sense: <?php if (!empty($this->items)) : ?> because you are not trying to access $this->items inside of it.
    – mickmackusa
    Oct 27 '20 at 14:21
  • Thanks very much, Mickmackusa. I will delete <?php if (!empty($this->items)) : ?>, is there any way to call always (not once)?
    – zhang
    Oct 28 '20 at 1:59
  • Generally speaking, don't you just want to do this? 3v4l.org/5ccG5
    – mickmackusa
    Oct 28 '20 at 3:11
0

I think, I solved it:

<?php foreach ($this->items as $article) : ?>
<?php if ($article->params->get('access-edit'))
        {
            $isEditable = true;
            break;
        }
?>

<?php foreach($article->jcfields as $jcfield){
    $article->jcFields[$jcfield->name] = $jcfield;
}
?>
<div><?php echo $article->jcFields['part-no']->value; ?>
<?php endforeach; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.