doulu0266 2012-04-20 10:19
浏览 33
已采纳

如何在最新新闻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??

  • 写回答

1条回答 默认 最新

  • dongliang9682 2012-04-20 10:49
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法