1
votes

I am using Joomla 3.4.8 and it's Article - Latest Module. That module showed only latest article's title but I want to show introtext and tags also. I was able to show the introtext but didn't able to show tags. Can anyone help me to figure it out? Here is my code given below.

<pre><code>foreach($list as $item):
echo $item->title;
echo $item->introText;
echo $item->tags->itemTag;
endforeach;</code></pre>

When I run this code get the error message:

Notice: Array to string conversion in F:\xampp\htdocs\rnd\joomla\tx_quicx\modules\mod_articles_latest\tmpl\default.php on line 37

Which corresponds to echo $item->tags->itemTag;

Thanks in advance.

2
Welcome to StackOverflow. What's the full error message? - Brandon
Hello Brandon, Here is the error: Notice: Array to string conversion in F:\xampp\htdocs\rnd\joomla\tx_quicx\modules\mod_itl_portfolio\tmpl\default.php on line 37 and my line number 37 is - echo $item->tags->itemTag; Thanks - Asif Islam

2 Answers

2
votes

The tags field is an array.

You have to reference the element number you want from that field and then reference its itemTag.

foreach($list as $item):
echo $item->title;
echo $item->introText;
echo $item->tags[0]->itemTag;
endforeach;

Will get the first (0th) item tag. If you want all item tags for all items, you'll have to iterate through all elements of the tags array.

1
votes

This code solve my issue.

foreach($list as $item){
    echo $item->title;
    echo $item->introText;
    foreach($item->tags->itemTags as $tag){
        echo $tag->title;
    }
}

Thanks Brandon