[英]How to get article intro Image by Id Joomla 3
我正在尝试在Joomla 3.0中获取Article的介绍图像我发现此代码并且它不起作用:
$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'} . "'>";
我得到的信息是JRequest::getInt
是折旧的,当我想要获得$pictures
我得到了null。 有人可以告诉我如何通过文章ID获得1个介绍图像?
请尝试使用此代码:
$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;
祝好运!
<?php foreach ($this->items as $i => $article) : ?>
<?php $image = json_decode($article->images,true)['image_intro']; ?>
<?php if(!empty($image)){ ?>
<img src="<?=$image?>" alt="">
<?php } ?>
<?php endforeach; ?>
使用上面的代码。 这个对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.