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

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

问题描述:

I need to get separated the image and text of the article, the problem is that they are in one field of the database, so how can i make that in the view i can put the image separated from the text? because i can't put the image and the text togheter, is a mess

<? 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; ?>

so i need to put the image like this $item->image - this is what i want, but in joomla latestnews_mod, there is no field with image, and i don't know if i need to write my own, or edit this module, or i need to use other module for this ? And also i cannot get the field $item->category that i need, there is only the CAT_ID, and how can i get the category field??

我需要将文章的图像和文字分开,问题是它们在一个字段中 数据库,那么如何才能在视图中将图像与文本分开? 因为我不能把图像和文字放在一边,是一团糟 p>

 &lt;?  foreach($ list as $ item):?&gt; 
 
&lt;?
 
 $ year = date('Y',strtotime($ item-&gt; created)); 
 $ month = date(  'm',strtotime($ item-&gt; created)); 
 $ day = date('d',strtotime($ item-&gt; created)); 
 
 
 $ shortDescription = cutString($ item  - &gt; introtext,100); 
 
?&gt; 
&lt; div class =“footerItem”&gt; 
&lt;?= $ day;  ?&gt;  - &lt;?= $ month;  ?&gt;  - &lt;?= $ year;  ?&gt; 
&lt; p&gt;&lt; a href =“&lt;?= $ item-&gt; link;?&gt;”&gt;&lt;?= $ item-&gt; title;  ?&gt;&lt; / a&gt;&lt; / p&gt; 
&lt; p&gt; 
&lt;?= $ shortDescription;  ?&gt; 
&lt; / p&gt; 
&lt; / div&gt; 
&lt;?php endforeach;  ?&gt; 
  code>  pre> 
 
 

所以我需要把图像放在这个$ item-&gt;图像 - 这就是我想要的,但在joomla latestnews_mod中,没有 字段与图像,我不知道我是否需要自己编写,或编辑此模块,或者我需要使用其他模块吗? 而且我也无法获得我需要的字段$ item-&gt;类别,只有CAT_ID,我怎样才能获得类别字段?? p> div>

I've lost touch with Joomla a bit, so it's entirely possible this is not the easiest way, but could you use regex to pull out the image from the intro-text if it's not specifically given?

You'd need a pattern something like: <img\b[^>]+?src\s*=\s*['"]?([^\s'"?#>]+)

That's taken from this question: Regex to find the first image in an image tag in an HTML document

EDIT: Example using 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] . "
";
?>

Do note that this is relatively untested, may not work and if it does, may miss cases with bad markup!