I am trying to customize the the category list of my website. So I have a menu option that shows the list of all article is a certain category. In this list I would like to show the into image of the article too. But unfortunately I cannot find the path of this intro image of each article to put it in the '' tag.

This code takes the first image in the article. Which is not what I want.

$text = $article->introtext;
if(preg_match('/<\s*img[^>]+>/Ui', $text, $matches)){

   $text = str_replace($image,'',$text);
if ($matches) {
$image = str_replace('img src="','img width="150px" src="/demo/persianlondon/',$image);
$image = str_replace("caption","", $image);
echo '' . $image . '';
else {echo '<img width="150px" src="http://goo.gl/k47rNN" class="defaultArticleImage" />';}


So I need to get the intro image url and set it for $image. Any idea to do it?

  • To give your question context, please provide some sample data and your expected result. What does $article->introtext contain? I am sure I can provide you with an optimized solution if you can clarify the posted question. – mickmackusa Nov 30 '18 at 1:10

That code is looking in the article text you need to is in the images call. It is json encoded so you have to decoded it first.

$images  = json_decode($this->item->images);

echo $images->image_intro;

Have a look at the com_content/article/default.php template to see some of the other parts of data you can use for images.

  • Thank you for you post. I just couldnt get it working. Can you provide the full code, or just tell me where should I add it to? – Danial Jul 31 '14 at 15:08
  • 1
    Try variations on the object as I am not sure the code in the template you are using: $article->images or $item->images or $article->params->get('images') it will be around there somewhere on the main object – tristanbailey Sep 13 '14 at 22:30
  • The above is what I used. Don't forget to add the php tags obviously. I did it this way. <?php $images = json_decode($this->item->images); $introImage = $images->image_intro; ?> ...src="<?php echo $introImage ; ?>".... – Eoin May 24 '16 at 16:38

The above works for me in the category blog view, it might be different in category list view. Don't forget to add the php tags obviously. You could always use <?php // print_r($images); ?> to print all of the available options which might give you a clue. Or potentially this <?php // print_r($this->item); ?>

I did it this way.

$images         = json_decode($this->item->images); 
$introImage   = $images->image_intro;

...src="<?php echo $introImage ; ?>"....

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.