1

I'm trying to get Article's intro Image in Joomla 3.3 I found this code and it's not working:

$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 info that JRequest::getInt is depreciated and i when i'm trying to var dump $pictures i got null. Can somebody tell me how to get 1 intro image by article id ?

3

JRequest is deprecated.

It's been replaced by JInput, so your line:

$article->load(JRequest::getInt("id")); // Get Article ID 

would need to change to:

$id = JFactory::getApplication()->input->getInt('id');
$article->load($id); // Get Article 
  • It's a good idea to use JInput but I think JRequest is valid right now (for Joomla 3.3). – Farahmand Sep 15 '14 at 19:14
1

Not sure accessing the article is the issue, although you should use JInput veruses JRequest, it shouldn't prevent you from getting the data yet. Unless there is a new technique I've missed in my old age, you are not referencing the image properties properly, try this:

echo "<img src='" . $pictures->image_intro . "' alt='" . $pictures->image_intro_alt . "'>";

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.