Skip to main content
tags edited, improved formatting
Source Link
mickmackusa
  • 4.8k
  • 4
  • 18
  • 48
<div class="row" id="interested-in">
    <div class="col-12">

        <h2>Heading Here</h2>
        <div class="row">

            <?php

            use Joomla\CMS\Language\Text;
            use Joomla\CMS\Date\Date;
            use Joomla\CMS\Factory;

            $db = JFactory::getDbo();


            $query = $db->getQuery(true);

            $query->select('*');
            $query->from('#__content');
            $query->order('id DESC ');
            $query->limit('3');

            $db->setQuery((string)$query);
            $res = $db->loadObjectList();



            $i = 0;
            foreach ($res as $r) {
                $introimage = $r->images;
                $id = $r->id;
                $title = $r->title;
                $published = $r->publish_up;
                $intro = $r->introtext;
                if (++$i > 3) break;

                echo '<div class="col-lg-4 col-md-6">';
                echo '<div class="card">';
                if ($introimage == null || $introimage == '/') {
                    echo '<div class="card-img-top holding-image" alt="' . $title . '"></div>';
                } else {
                    echo '<img class="card-img-top" src="' . $introimage . '" alt="' . $r->title . '"/>';
                }
                echo '<div class="card-body">';
                echo '<a href="' . JRoute::_('index.php?option=com_content&view=article&id=' . $id) . '">';
                echo '<h5 class="card-title mb-4">'.$title.'</h5>';
                echo '</a>';
                echo '<time datetime="'. $published . '" class="mb-2 text-muted">'.$published.'</time>';
                echo '<p class="card-text">'.mb_strimwidth("$intro", 0, 80, "...").'</p>';
                echo '</div>';
                echo '</div>';
                echo '</div>';
            } ?>
        </div>
    </div>
</div>
Call to a member function format() on string

Call to a member function format() on string

    <h2>Heading Here</h2>
    <div class="row">

        <?php

        use Joomla\CMS\Language\Text;
        use Joomla\CMS\Date\Date;
        use Joomla\CMS\Factory;

        $db = JFactory::getDbo();


        $query = $db->getQuery(true);

        $query->select('*');
        $query->from('#__content');
        $query->order('id DESC ');
        $query->limit('3');

        $db->setQuery((string)$query);
        $res = $db->loadObjectList();



        $i = 0;
        foreach ($res as $r) {
            $introimage = $r->images;
            $id = $r->id;
            $title = $r->title;
            $published = $r->publish_up;
            $intro = $r->introtext;
            if (++$i > 3) break;

            echo '<div class="col-lg-4 col-md-6">';
            echo '<div class="card">';
            if ($introimage == null || $introimage == '/') {
                echo '<div class="card-img-top holding-image" alt="' . $title . '"></div>';
            } else {
                echo '<img class="card-img-top" src="' . $introimage . '" alt="' . $r->title . '"/>';
            }
            echo '<div class="card-body">';
            echo '<a href="' . JRoute::_('index.php?option=com_content&view=article&id=' . $id) . '">';
            echo '<h5 class="card-title mb-4">'.$title.'</h5>';
            echo '</a>';
            echo '<time datetime="'. $published . '" class="mb-2 text-muted">'.$published.'</time>';
            echo '<p class="card-text">'.mb_strimwidth("$intro", 0, 80, "...").'</p>';
            echo '</div>';
            echo '</div>';
            echo '</div>';
        } ?>
    </div>
</div>
Call to a member function format() on string
<div class="row" id="interested-in">
    <div class="col-12">

        <h2>Heading Here</h2>
        <div class="row">

            <?php

            use Joomla\CMS\Language\Text;
            use Joomla\CMS\Date\Date;
            use Joomla\CMS\Factory;

            $db = JFactory::getDbo();


            $query = $db->getQuery(true);

            $query->select('*');
            $query->from('#__content');
            $query->order('id DESC ');
            $query->limit('3');

            $db->setQuery((string)$query);
            $res = $db->loadObjectList();



            $i = 0;
            foreach ($res as $r) {
                $introimage = $r->images;
                $id = $r->id;
                $title = $r->title;
                $published = $r->publish_up;
                $intro = $r->introtext;
                if (++$i > 3) break;

                echo '<div class="col-lg-4 col-md-6">';
                echo '<div class="card">';
                if ($introimage == null || $introimage == '/') {
                    echo '<div class="card-img-top holding-image" alt="' . $title . '"></div>';
                } else {
                    echo '<img class="card-img-top" src="' . $introimage . '" alt="' . $r->title . '"/>';
                }
                echo '<div class="card-body">';
                echo '<a href="' . JRoute::_('index.php?option=com_content&view=article&id=' . $id) . '">';
                echo '<h5 class="card-title mb-4">'.$title.'</h5>';
                echo '</a>';
                echo '<time datetime="'. $published . '" class="mb-2 text-muted">'.$published.'</time>';
                echo '<p class="card-text">'.mb_strimwidth("$intro", 0, 80, "...").'</p>';
                echo '</div>';
                echo '</div>';
                echo '</div>';
            } ?>
        </div>
    </div>
</div>

Call to a member function format() on string

added 1272 characters in body; edited tags
Source Link
RustyJoomla
  • 2.1k
  • 4
  • 25
  • 33

I have written the following, which is working but I don't thinkneed to json_decode the db query is rightimages in order to show the introimage:

    <h2>Heading Here</h2>
    <div class="row">

        <?PHP
php

        use Joomla\CMS\Language\Text;
        use Joomla\CMS\Date\Date;
        use Joomla\CMS\Factory;

        $db = JFactory::getDbo(); 


        $query = $db->getQuery(true);

        $query->select('*');
        $query->from('#__content');
        $query->order('id DESC ');
        $query->limit('3');

        $db->setQuery((string)$query);
        $res = $db->loadObjectList(); 



        $i = 0;
        foreach ($res as $r) {
            $introimage = $r->images;
            $id = $r->id;
            $title = $r->title;
            $published = $r->publish_up;
            $intro = $r->introtext;
            if (++$i > 3) break;

            echo '<div class="col-lg-4 col-md-6">';
            echo '<div class="card">';
            if ($introimage == null || $introimage == '/') {
                echo '<div class="card-img-top holding-image" alt="' . $title . '"></div>';
            } else {
                echo '<img class="card-img-top" src="' . $introimage . '" alt="' . $title$r->title . '"/>';
            }
            echo '<h2>''<div class="card-body">';
            echo '<a href="' . $titleJRoute::_('index.php?option=com_content&view=article&id=' .''; $id) . '">';
            echo '<h5 class="card-title mb-4">'.$title.'</h5>';
            echo '</a>';
            echo '<time datetime="' . $published . '">''" .class="mb-2 text-muted">'.$published.'</time>';
            echo '<p class="card->format(Text::_text">'.mb_strimwidth('DATE_FORMAT_LC'))"$intro", .0, 80, "...").'</time>';p>';
            echo '$intro';'</div>';
}            echo '</div>';
            echo '</div>';
        } ?>
    </div>
</div>

I also need to work out a way of only showing the intro image fromecho the images fielddate in the table as this is JSON currently.a different format, I've tried

echo '<time datetime="'. $published . '" class="mb-2 text-muted">'.$published->format(Text::_('DATE_FORMAT_LC')).'</time>';

But that gives me an error:

Call to a member function format() on string

I have written the following but I don't think the db query is right:

<?PHP


    use Joomla\CMS\Language\Text;
    use Joomla\CMS\Date\Date;
    use Joomla\CMS\Factory;

    $db = JFactory::getDbo();
    $query = $db->getQuery(true);

    $query->select('*');
    $query->from('#__content');
    $query->order('id DESC ');
    $query->limit('3');

    $db->setQuery((string)$query);
    $res = $db->loadObjectList();

    foreach($res as $r){
        $introimage = $r->images;
        $title = $r->title;
        $published = $r->publish_up;
        $intro = $r->introtext;

echo '<img src="' . $introimage . '" alt="' . $title . '"/>';
echo '<h2>'. $title .'';
echo '<time datetime="' . $published . '">' . $published->format(Text::_('DATE_FORMAT_LC')) . '</time>';
echo '$intro';
}

?>

I also need to work out a way of only showing the intro image from the images field in the table as this is JSON currently.

I have written the following, which is working but I need to json_decode the images in order to show the introimage:

    <h2>Heading Here</h2>
    <div class="row">

        <?php

        use Joomla\CMS\Language\Text;
        use Joomla\CMS\Date\Date;
        use Joomla\CMS\Factory;

        $db = JFactory::getDbo(); 


        $query = $db->getQuery(true);

        $query->select('*');
        $query->from('#__content');
        $query->order('id DESC ');
        $query->limit('3');

        $db->setQuery((string)$query);
        $res = $db->loadObjectList(); 



        $i = 0;
        foreach ($res as $r) {
            $introimage = $r->images;
            $id = $r->id;
            $title = $r->title;
            $published = $r->publish_up;
            $intro = $r->introtext;
            if (++$i > 3) break;

            echo '<div class="col-lg-4 col-md-6">';
            echo '<div class="card">';
            if ($introimage == null || $introimage == '/') {
                echo '<div class="card-img-top holding-image" alt="' . $title . '"></div>';
            } else {
                echo '<img class="card-img-top" src="' . $introimage . '" alt="' . $r->title . '"/>';
            }
            echo '<div class="card-body">';
            echo '<a href="' . JRoute::_('index.php?option=com_content&view=article&id=' . $id) . '">';
            echo '<h5 class="card-title mb-4">'.$title.'</h5>';
            echo '</a>';
            echo '<time datetime="'. $published . '" class="mb-2 text-muted">'.$published.'</time>';
            echo '<p class="card-text">'.mb_strimwidth("$intro", 0, 80, "...").'</p>';
            echo '</div>';
            echo '</div>';
            echo '</div>';
        } ?>
    </div>
</div>

I also need to echo the date in a different format, I've tried

echo '<time datetime="'. $published . '" class="mb-2 text-muted">'.$published->format(Text::_('DATE_FORMAT_LC')).'</time>';

But that gives me an error:

Call to a member function format() on string
added 113 characters in body
Source Link
RustyJoomla
  • 2.1k
  • 4
  • 25
  • 33
Loading
Source Link
RustyJoomla
  • 2.1k
  • 4
  • 25
  • 33
Loading