Hi I'm using this template on a new joomla 4 installation: ja_flix
My question is relative to the article intro image, at the moment it seems that it used the article intro image or (if empty) a place holder image. My question is how show the first image present in the article content if no intro image has been added?
at the moment in the intro.php files there is this code:

if(!$thumbnail) {
	if((isset($images->image_intro) && !empty($images->image_intro))) {
		if(preg_match('/http/',$images->image_intro,$matches)){
			$thumbnail = $images->image_intro;
		}else{
			$thumbnail = JURI::root(true) .'/'. htmlspecialchars($images->image_intro, ENT_COMPAT, 'UTF-8');
		}
	} else {
		$thumbnail = JURI::base() . '/templates/' . $template . '/images/blank-intro.png';
	}
}

I need to show the first image in article if no intro image is present and the placeholder image if there is no image in the article content.
I hope some one can give me some suggestion
thanks
Fabrizio

HI Fabrizio,

May I know which page you want to show the first article image?

If it's category blog / featured articles page, it must take the intro image of each article - this is default behavior of Joomla. You will have to customize code to achieve that.

    saguaros
    Hi Saguaros thanks for your reply.
    yes I need to show the image in the category blog / featured articles.
    I know that I'will have to customize the code, What I need is some help to customize the code as desired.
    :-)
    any help will be appreciated.
    Fabrizio

      Thank you for your information rossiello , I sent this to our developer team and I will get back to you as soon as I got an update from the team.

      Best regards.

      Hi rossiello,
      Open the intro.php file in the "../ja_flix/html/layouts/joomla/content/image/" folder and replace above PHP code section by below PHP code section:

      $item_content = $displayData->fulltext;
      
      if(!$thumbnail) {
      	if((isset($images->image_intro) && !empty($images->image_intro))) {
      		if(preg_match('/http/',$images->image_intro,$matches)){
      			$thumbnail = $images->image_intro;
      		}else{
      			$thumbnail = JURI::root(true) .'/'. htmlspecialchars($images->image_intro, ENT_COMPAT, 'UTF-8');
      		}
      	} else {
      		preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $item_content, $image);
      		if($image['src']) {
      			$thumbnail = JURI::root(true) . '/' . $image['src'];
      		}else{
      			$thumbnail = JURI::base() . '/templates/' . $template . '/images/blank-intro.png';
      		}
      		
      	}
      }

      Save and reload your website to view all changes.

      Ehi cssyeah
      Many thanks for your help, the article image now is used as intro image but not the first image in the article, what I see is almost always the last image (the author avatar for example) in the article.
      is there a way to let the system use the very first image present in each article?
      Thanks again for your help
      Fabrizio

      Please have a look here:
      https://beta.ilfoglietto.it/
      as you can see clicking on an article the image that is used as intro image is never the first one in the article but the last one

      Could you share the super admin account and tell us the article name so we can check?

        This message is visible to Moderators only
        hidden content

        Hi Fabrizio,

        I'm not familiar with native language on your site, could you share the URL of page that it shows the wrong image?

        Do you mean the module on the right sidebar, right? let me check and will get back to you.

        We updated this file: /templates/ja_flix/html/layouts/joomla/content/image/intro.php

        Kindly check.

        introphp.zip
        2kB

        Many thanks for your help, now it works as expected
        Thanks a lot

        Write a Reply...
        You need to Login to view replies.