1

As a way of presenting the "freshness" of my website's content, I want to present the date of the most recently created/modified article.

I need to display the last change date across all articles on my home page.

I know I can get an individual article's last modification date like this:

$this->item->modified

But the question is : Can I get the last change date for all articles?

2
  • Are you adding the last modified date to a list of articles that is already on the page? Or do you need to make a new database call to get the data and then display it? Dec 3, 2021 at 22:24
  • @jamesgarrett I believe I need to make the database call as I need the last modification date for all the articles on the website. The goal is to display the last modification date of the website.
    – web-tiki
    Dec 6, 2021 at 8:50

1 Answer 1

2

The SQL that returns the most recent modified date across all your articles:

SELECT `modified` FROM `#__content` GROUP BY `modified` ORDER BY `modified` DESC LIMIT 1

Then you would need to build a Joomla select query in PHP:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('modified')));
$query->from($db->quoteName('#__content'));
$query->group('modified');
$query->order('modified DESC');
$db->setQuery($query);
$mostrecent = $db->loadResult();
echo $mostrecent;

You would then further convert the result into a date (as the result is returned as a string) and then adjust how your most recent date is formatted:

$thedate = date_create($mostrecent);
echo '<em>Site content last modified on '. date_format($thedate,'l jS F Y').'<em>';

Which at the time of my reply would return:

Site content last modified on Saturday 11th December 2021

2
  • BTW To test that, I've used Regular Labs Sourcerer extension to place the code into an article by pasting the above code between {source}<?php ?>{/source} tags. Dec 11, 2021 at 7:57
  • Tested on a live site and it works great. I added it in an article override. Thank you !
    – web-tiki
    Jan 18, 2022 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.