[英]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" />';}
?>
所以我需要获取介绍图片网址并将其设置为$image
。 有任何想法吗?
如果您正在谈论某个类别的博客视图,那么如果将其放在文件中,则此代码将写出带有路径的介绍图片文件名:
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] =>
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.