如何在最新新闻joomla中添加图像


How to add images in latest news joomla

我需要将文章的图像和文本分开,问题是它们在数据库的一个字段中,那么我怎样才能在视图中将图像与文本分开呢? 因为我不能把图像和文本切换,是一团糟

<? foreach ($list as $item) :  ?>
                    <?
                        $year = date('Y', strtotime($item->created));
                        $month = date('m', strtotime($item->created));
                        $day = date('d', strtotime($item->created));

                        $shortDescription = cutString($item->introtext, 100);
                    ?>
                    <div class="footerItem">
                    <?= $day; ?>-<?= $month; ?>-<?= $year; ?>
                    <p><a href="<?= $item->link; ?>"><?= $item->title; ?></a></p>
                    <p>
                    <?= $shortDescription; ?>
                    </p>
                    </div>
<?php endforeach; ?>

所以我需要像这样放置图像 $item->图像 - 这就是我想要的,但是在 Joomla latestnews_mod 中,没有带有图像的字段,我不知道我是否需要编写自己的,或者编辑这个模块,或者我需要为此使用其他模块?而且我无法获得我需要的字段$item->类别,只有CAT_ID,我如何获得类别字段?

我与 Joomla 有点失去联系,所以这完全有可能不是最简单的方法,但是如果没有特别给出,您可以使用正则表达式从介绍文本中提取图像吗?

你需要一个模式,如下所示: <img'b[^>]+?src's*='s*['"]?([^'s'"?#>]+)

这取自这个问题:正则表达式在HTML文档中的图像标签中查找第一个图像

编辑:使用preg_match的示例:

<?php
  // This is the Regex pattern from above.
  $pattern = '/<img'b[^>]+?src's*='s*[''"]?([^'s''"?#>]+)/'; 
  // Perform the search, matches will be stored in $matches
  preg_match($pattern, $item->introtext, $matches ); 
  echo "Image src is: " . $matches[1] . "'n";
?>

请注意,这是相对未经测试的,可能无法正常工作,如果确实如此,可能会错过标记错误的情况!