[英]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.