简体   繁体   English

如何获得文章介绍图片来自Id Joomla 3

[英]How to get article intro Image by Id Joomla 3

I'm trying to get Article's intro Image in Joomla 3.0 I found this code and it's not working: 我正在尝试在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'} . "'>";

I got info that JRequest::getInt is depreciated and i when i'm trying to get $pictures i got null. 我得到的信息是JRequest::getInt是折旧的,当我想要获得$pictures我得到了null。 Can somebody tell me how to get 1 intro image by article id ? 有人可以告诉我如何通过文章ID获得1个介绍图像?

Please 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! 祝好运!

<?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; ?>

Use above code. 使用上面的代码。 It works for me. 这个对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM