簡體   English   中英

如何獲取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" />';}
?>

所以我需要獲取介紹圖片網址並將其設置為$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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM