-
AuthorPosts
-
November 19, 2017 at 8:39 pm #1075185
I would like to display the time elapsed since and article was posted by subtracting it from the current time. Any suggesstion?
Saguaros ModeratorSaguaros
- Join date:
- September 2014
- Posts:
- 31405
- Downloads:
- 237
- Uploads:
- 471
- Thanks:
- 845
- Thanked:
- 5346 times in 4964 posts
November 20, 2017 at 10:02 am #1075354Any sample of date format that you’re mentioning?
November 20, 2017 at 10:28 am #1075359Hello, thank you for fast reply. Elapsed time from publish article time. If article was published 2 hours ago, I need that time to visible (hours, minutes)
Saguaros ModeratorSaguaros
- Join date:
- September 2014
- Posts:
- 31405
- Downloads:
- 237
- Uploads:
- 471
- Thanks:
- 845
- Thanked:
- 5346 times in 4964 posts
November 21, 2017 at 3:17 am #1075556Hi,
You will need some customization to achieve that. Here is my tweak:
1) Go to file: [root]/templates/ja_teline_v/helper.phpAdd a new function called relTime:
public static function relTime($timespan, $granularity = 1) { static $units = array( 'YEAR' => 31536000, 'MONTH' => 2592000, 'WEEK' => 604800, 'DAY' => 86400, 'HOUR' => 3600, 'MIN' => 60, 'SEC' => 1, ); $output = ''; if(!ctype_digit($timespan)){ $timespan = strtotime($timespan); } $interval = time() - $timespan; $future = $interval < 0; if($future){ $interval = abs($interval); } foreach ($units as $key => $value) { if ($interval >= $value) { $output .= ($output ? ' ' : '') . JText::sprintf('TPL_RT_' . $key . (floor($interval / $value) != 1 ? 'S' : ''), floor($interval / $value)); $interval %= $value; $granularity--; } if ($granularity == 0) { break; } } return $output ? JText::sprintf($future ? 'TPL_RT_FUTURE' : 'TPL_RT_PAST', $output) : JText::_('TPL_RT_NOW'); }
It looks like this: http://prntscr.com/hd59dh
2) Open the file: [root]/templates/ja_teline_v/html/layouts/joomla/content/info_block/publish_date.php
Under the time tag, change it to:
<time datetime="<?php echo JHtml::_('date', $displayData['item']->publish_up, 'c'); ?>" itemprop="datePublished"> <?php echo JATemplateHelper::relTime($displayData['item']->publish_up); ?> <?php echo $displayData['item']->publish_up ?> </time>
3) Go to language file of template: [root]/language/en-GB/en-GB.tpl_ja_teline_v.ini
Add these language text:
TPL_RT_FUTURE ="in %s" TPL_RT_PAST ="%s ago" TPL_RT_NOW ="just now" TPL_RT_YEAR ="1 year" TPL_RT_YEARS ="%d years" TPL_RT_MONTH ="1 month" TPL_RT_MONTHS ="%d months" TPL_RT_WEEK ="1 week" TPL_RT_WEEKS ="%d weeks" TPL_RT_DAY ="1 day" TPL_RT_DAYS ="%d days" TPL_RT_HOUR ="1 hour" TPL_RT_HOURS ="%d hours" TPL_RT_MIN ="1 min" TPL_RT_MINS ="%d mins" TPL_RT_SEC ="1 sec" TPL_RT_SECS ="%d secs"
-
AuthorPosts
This topic contains 3 replies, has 2 voices, and was last updated by Saguaros 6 years, 12 months ago.
We moved to new unified forum. Please post all new support queries in our New Forum