Canada  united states of america usa  linkedinfacebook   Call Us Today: 866.646.6461

Get the article modified date from code in Joomla

joomlaThis is a code snippet which allows to get the article modified date from an article itself. This has to be done in a template (or other code). The first part is to identify the item as article and second part to extract the modified date of the article (Tested with Joomla 2.5):

 

$joomlaApp = JFactory::getApplication()->input;
$option = $joomlaApp->getCmd('option');
$view = $joomlaApp->getCmd('view');

if ($option == 'com_content' && $view == 'article'){
$currentArticleID = JFactory::getApplication()->input->get('id');
$db = JFactory::getDbo();
$query = $db->getQuery(true)
    ->select($db->quoteName('modified'))
    ->from($db->quoteName('#__content'))
    ->where('id = '. $db->Quote($currentArticleID));

$db->setQuery($query);
$result = $db->loadResult();
$objDateModified = new JDate($result);
$strDateModified = $objDateModified->format('Y-m-d');
}

The dates can be formatted differently, but this is for use with the Article Schema:

<script type="application/ld+json">
    {
      "@context" : "http://schema.org",
      "@type" : "Article",
      "datePublished" : "<?php echo $strDateModified; ?>"
    }
</script>

 ALT Technical is an IT Consulting company, offering IT support and website development for businesses and organizations.

Last updated Apr 7, 2019