0

I'm looking for some help with our website. So, we have this news site which gets lots and lots of new articles in short period of time and therefore it requires lots of journalists working on it.

The workflow would be much easier if we wouldn't have to set Intro Image or Full Text Image each time on each article to be shown in the blog layout next to the article.

Some 3rd party modules know how to pick any image from the content of the article. Since the website is online and 3rd party modules wouldn't be the best solution for us, I'm wondering is there any way to tell Joomla to pick any image from the article instead of just Intro Image or Full Text Image?

I've been working around php a bit but couldn't find any line that would help me.

Thanks, Jan

2
  • From what part of the article is the image you're trying to pull? is it from the intro text or the full text; Is the first occurrence or second or etc.? And, where are you trying to show the image? Is it 'category blog' pages?
    – cwps
    Commented Nov 3, 2016 at 7:16
  • The image is from full text, the first one that would appear in the article. I would like to show it in the category blog.
    – JxM
    Commented Nov 9, 2016 at 14:41

1 Answer 1

1

You can do the following in the overridden article layout file (e.g. templates/[your-template]/html/com_content/article/default.php):

  • Search for images using a regular expression
  • Use the first image found as a display image for your article (you can use a default image if no images are found)

For the regular expression used to find images, you can check this post where we searched for images in a K2 article (essentially used for Open Graph tags). The regular expression line should be exactly the same in your code.

3
  • Seems like this might help. Problem is, I'm not much of a programmer. I guess this is the part of the code you're reffering to? <?php if (isset($images->image_fulltext) && !empty($images->image_fulltext)) : ?> <?php $imgfloat = (empty($images->float_fulltext)) ? $params->get('float_fulltext') : $images->float_fulltext; ?> <div class="pull-<?php echo htmlspecialchars($imgfloat); ?> item-image"> <img <?php if ($images->image_fulltext_caption): (Part 1)
    – JxM
    Commented Nov 2, 2016 at 21:27
  • echo 'class="caption"' . ' title="' . htmlspecialchars($images->image_fulltext_caption) . '"'; endif; ?> src="<?php echo htmlspecialchars($images->image_fulltext); ?>" alt="<?php echo htmlspecialchars($images->image_fulltext_alt); ?>" itemprop="image"/> </div> <?php endif; ?> (Part 2)
    – JxM
    Commented Nov 2, 2016 at 21:30
  • Could you help me out a bit more, please?
    – JxM
    Commented Nov 2, 2016 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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