PDA

View Full Version : Total Guide How to add - Date to Listing tpl Block on Detail Page



Ameer Hassan
May 31, 2016, 12:22 PM
Hi Everyone,

I Have made Time Date For 2 language English and Arabic and Want to Share with You Here :)



Here Are The Steps:-

1.Go To ----> public_html/libs/smarty/plugins
And Create file called >>modifier.timeAgo.php<< "note: you can create another one for other language as i did >>modifier.timeAgo-ar.php <<

Then edit file and paste this code inside it :-

<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/


/**
* Smarty date modifier plugin
* Purpose: converts unix timestamps or datetime strings to words
* Type: modifier<br>
* Name: timeAgo<br>
* @author Stephan Otto
* @param string
* @return string
*/
function smarty_modifier_timeAgo( $date)
{
// for using it with preceding 'vor' index
$timeStrings = array( 'recently', // 0 <- now or future posts :-)
'second', 'second', // 1,1
'Minute','Minute', // 3,3
'hour', 'hour', // 5,5
'day', 'day', // 7,7
'week', 'week', // 9,9
'month', 'month', // 11,12
'year','year'); // 13,14
$debug = false;
$sec = time() - (( strtotime($date)) ? strtotime($date) : $date);

if ( $sec <= 0) return $timeStrings[0];

if ( $sec < 2) return $sec." ".$timeStrings[1];
if ( $sec < 60) return $sec." ".$timeStrings[2];

$min = $sec / 60;
if ( floor($min+0.5) < 2) return floor($min+0.5)." ".$timeStrings[3];
if ( $min < 60) return floor($min+0.5)." ".$timeStrings[4];

$hrs = $min / 60;
echo ($debug == true) ? "hours: ".floor($hrs+0.5)."<br />" : '';
if ( floor($hrs+0.5) < 2) return floor($hrs+0.5)." ".$timeStrings[5];
if ( $hrs < 24) return floor($hrs+0.5)." ".$timeStrings[6];

$days = $hrs / 24;
echo ($debug == true) ? "days: ".floor($days+0.5)."<br />" : '';
if ( floor($days+0.5) < 2) return floor($days+0.5)." ".$timeStrings[7];
if ( $days < 7) return floor($days+0.5)." ".$timeStrings[8];

$weeks = $days / 7;
echo ($debug == true) ? "weeks: ".floor($weeks+0.5)."<br />" : '';
if ( floor($weeks+0.5) < 2) return floor($weeks+0.5)." ".$timeStrings[9];
if ( $weeks < 4) return floor($weeks+0.5)." ".$timeStrings[10];

$months = $weeks / 4;
if ( floor($months+0.5) < 2) return floor($months+0.5)." ".$timeStrings[11];
if ( $months < 12) return floor($months+0.5)." ".$timeStrings[12];

$years = $weeks / 51;
if ( floor($years+0.5) < 2) return floor($years+0.5)." ".$timeStrings[13];
return floor($years+0.5)." ".$timeStrings[14];
}

?>

2.Now go to Use This to call the listing date in tpl file --> to Get Full Time use this

{$listing_data.Date|date_format:$smarty.const.RL_D ATE_FORMAT} - {$listing_data.Date|timeAgo} ago

And if you want just Time Ago from posting ad use this only:-

{$listing_data.Date|timeAgo} ago

3.This one used in listing detail block for category listing block or listing.tpl just use this:

Added: {$listing.Date|timeAgo} ago

Hope everyone be happy :)

My Regards
Ameer

Sanjay Pattar
May 31, 2016, 05:52 PM
Dear Ameer,

nice to see it worked for you. I tried but point 2 and 3 is not very clear.

Like in your point 1 we created file name modifier.timeAgo.php in public_html/libs/smarty/plugins folder and copy pasted below code.

In point 2, which file we have to put code and exact line were to put code.

In point 3 as well, in which file we have to do change and were to put code.

Please mention file path and file name were we have to make change, next exact line were we have to past your code.

thanks hope it will work for us as well.

thanks for your help.

Ameer Hassan
May 31, 2016, 10:43 PM
Hi Sanjay

->>>About point 2 you can put code in
public_html/templates/YourTEmplate/tpl/controllers/listing_details.tpl

Now edit listing_details.tpl

Find

<section class="main-section">
and add This Code bellow it

{$listing_data.Date|date_format:$smarty.const.RL_D ATE_FORMAT} - {$listing_data.Date|timeAgo} ago
To show the Date over image on listing Detail Page :)


- >>>About point 3 you can put code in
public_html/templates/YourTEmplate/tpl/blocks/listing.tpl

Edit listing.tpl
Find

<li class="system">
and add code before it

Added: {$listing.Date|timeAgo} ago
To show Date for ads in category listing page.


[And do not forget to add some custom css style to it]

And tell me if you still can not put it won't take more than 10 min :)

Regards
Ameer

Sanjay Pattar
June 2, 2016, 08:01 PM
Dear Ameer,

Thanks a lot i able to put the code successfully.

but I dont know how to write css code, My output is not showing like it is showing on your site.

I wanted similar to as it is shown on your site. with 'Eye icon shows, watch icon date time, location icon with city name', with blue color font were to change in css file, please tell us how to do it.

Thanks in advance.

Regards
SP

benyezza
June 4, 2016, 01:19 AM
thanks for sharing

Ameer Hassan
June 4, 2016, 12:13 PM
Dear kirby-nabil,

You welcome :)

Fadil Asani
August 5, 2016, 11:25 PM
Can you make one where it says "expires in" where it show how much time there is left until it expires. Or just the date on when it expires.

Ameer Hassan
November 8, 2016, 02:10 AM
I think i could do that with feature ads

Tariq hamed Ahmed
November 20, 2017, 10:00 AM
Thank you for this :)