0

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

BlareStriker
  • 235
  • 1
  • 4
  • 14
  • be more specific, like what you are trying to do?? – jogesh_pi Apr 20 '12 at 10:24
  • i am trying to set in the view: short_description, image, and link, but the problem is that the image can be in the place of the short description if the user puts the image first in the wyswyg, and also i don't see any way to put the image separated(anywhere i want), but not togheter, how can i solve this? i am using the latestnews_mod – BlareStriker Apr 20 '12 at 10:29
  • and what version of joomla you are using?? Also any example if you have something like.. – jogesh_pi Apr 20 '12 at 10:31
  • i am using joomla 1.7,
    = $day; ?>-= $month; ?>-= $year; ?>

    = $item->title; ?>

    = $shortDescription; ?>

    .... so you see that i am trying to put from the item fields in the view, but i want to get the image from this latestnews_mod, is that possible?? or i will need to write my own??, or is there other module for this?? because there is no field with the path to the image, Images and text in WYSYG are combined and
    – BlareStriker Apr 20 '12 at 10:39
  • then inserted in the DB in one field(Introtext) or (fulltext), Thats the problem – BlareStriker Apr 20 '12 at 10:42

1 Answers1

2

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] . "\n";
?>

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

Community
  • 1
  • 1
n00dle
  • 5,949
  • 2
  • 35
  • 48
  • and what function i need to use to do that? – BlareStriker Apr 20 '12 at 10:54
  • You'd want `preg_match`. http://php.net/manual/en/function.preg-match.php should give you a bit more information on it. I'll give a quick (untested) example in my answer now. – n00dle Apr 20 '12 at 11:17