How to get article intro Image by Id Joomla 3
I'm trying to get an intro Image article in Joomla 3.0 I found this code and it doesn't work:
$article = JTable::getInstance("content");
$article->load(JRequest::getInt("id")); // Get Article ID
$article_images = $article->get("images"); // Get image parameters
$pictures = json_decode($article_images); // Split the parameters apart
// Print the image
echo "<img src='" . $pictures->{'image_intro'} . "' alt='" . $pictures->{'image_intro_alt'} . "'>";
I got information about what is being JRequest::getInt
depreciated and I $pictures
got null when I try to get it . Can someone tell me how to get 1 intro image by article id?
+4
source to share
2 answers
Try with this code:
$article_id = JFactory::getApplication()->input->get('id'); // get article id
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('images'))
->from($db->quoteName('#__content'))
->where('id = '. $db->Quote($article_id));
$db->setQuery($query);
$result = $db->loadResult();
$intro_image = json_decode($result)->image_intro;
echo $intro_image;
Good luck!
+3
source to share