如何获得joomla文章的介绍图像


How to get the intro image of a joomla article

我正在尝试自定义我的网站的类别列表。所以我有一个菜单选项,显示所有文章的列表是一个特定的类别。在这个列表中,我也想展示文章的图像。但不幸的是,我找不到每篇文章的介绍图片的路径,无法将其放在"标签"中。

该代码获取本文中的第一个图像。这不是我想要的。

<?php
$text = $article->introtext;
if(preg_match('/<'s*img[^>]+>/Ui', $text, $matches)){
   $image=$matches[0];
   $text = str_replace($image,'',$text);
}
if ($matches) {
$image = str_replace('img src="','img width="150px" src="/demo/persianlondon/',$image);
$image = str_replace("caption","", $image);
echo '' . $image . '';
}
else {echo '<img width="150px" src="http://goo.gl/k47rNN" class="defaultArticleImage" />';}
?>

所以我需要获得介绍图像url并将其设置为$image。有什么办法吗?

如果您谈论的是一个类别的博客视图,如果您将其放入file:

,则此代码将写出带有path的介绍图像文件名。

jroot/component/com_content/views/category/tmpl/blog.php或在模板覆盖的blog.php文件中。

$article_items = $this->get('lead_items');
foreach ($article_items as $item) {
  $imageObj = json_decode($item->images);
  echo $imageObj->image_intro;
}

$imageObj:

stdClass Object
 (
   [image_intro] => 
   [float_intro] => 
   [image_intro_alt] => 
   [image_intro_caption] => 
   [image_fulltext] => 
   [float_fulltext] => 
   [image_fulltext_alt] => 
   [image_fulltext_caption] => 
 )