简体   繁体   English

如何获取joomla文章的介绍图片

[英]How to get the intro image of a joomla article

I am trying to customize the the category list of my website. 我正在尝试自定义网站的类别列表。 So I have a menu option that shows the list of all article is a certain category. 所以我有一个菜单选项,显示所有文章的列表都是某个类别。 In this list I would like to show the into image of the article too. 在此列表中,我也想显示文章的图片。 But unfortunately I cannot find the path of this intro image of each article to put it in the '' tag. 但不幸的是,我找不到每篇文章的介绍图片的路径来将其放在''标签中。

This code takes the first image in the article. 这段代码拍摄了文章中的第一张图片。 Which is not what I want. 这不是我想要的。

<?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" />';}
?>

So I need to get the intro image url and set it for $image . 所以我需要获取介绍图片网址并将其设置为$image Any idea to do it? 有任何想法吗?

If you are talkin about blog view of a category, this code will write out the intro image filename with path, if you put it in file: 如果您正在谈论某个类别的博客视图,那么如果将其放在文件中,则此代码将写出带有路径的介绍图片文件名:

jroot/component/com_content/views/category/tmpl/blog.php or in the template overrided blog.php file. 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;
}

other variables of $imageObj : $ 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.

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