fetching Full Article Image with php? Topic is solved

General questions relating to Joomla! 5.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Post Reply
SocketPup
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 134
Joined: Thu Mar 14, 2024 7:00 am

fetching Full Article Image with php?

Post by SocketPup » Mon Apr 08, 2024 5:09 pm

In my template override for article categories, I am able to fetch the title of each article using the following:

Code: Select all

<h1 class="h-4"><?php echo $this->escape($article->title); ?></h1>
Is there a similar way of also fetching the Intro Image or Full Article Image? If so, how do I do this?

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 25057
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: fetching Full Article Image with php?

Post by pe7er » Mon Apr 08, 2024 8:03 pm

The article contains an images field where both the intro and full image can stored in JSON format.
To display them you could use something like:

Code: Select all

<?php
$images = json_decode($article->images);

echo '<img src="' . $this->escape($images->image_intro) . '" alt="Intro Image">';
echo '<img src="' . $this->escape($images->image_fulltext) . '" alt="Full Image">';
?>
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

SocketPup
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 134
Joined: Thu Mar 14, 2024 7:00 am

Re: fetching Full Article Image with php?

Post by SocketPup » Tue Apr 09, 2024 7:16 am

pe7er wrote: Mon Apr 08, 2024 8:03 pm The article contains an images field where both the intro and full image can stored in JSON format.
To display them you could use something like:

Code: Select all

<?php
$images = json_decode($article->images);

echo '<img src="' . $this->escape($images->image_intro) . '" alt="Intro Image">';
echo '<img src="' . $this->escape($images->image_fulltext) . '" alt="Full Image">';
?>
Thanks, that's exactly what I was looking for!

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 25057
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: fetching Full Article Image with php?

Post by pe7er » Tue Apr 09, 2024 9:25 am

you're welcome!
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com


Post Reply

Return to “General Questions/New to Joomla! 5.x”