Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
general-topic
the function nicedate and other languages
Avatar
David H
Member
Free Members
sp_UserOfflineSmall Offline
Dec 31, 2013 - 4:27 am

Hi,

Your function- sp_nicedate() is nice.

It show something like:

2 days ago.

It is build in the sp-api-timezone.php

of course I can change this template but with the first update it will be gone...

I made a separate Theme which there I can do changes without being afraid from updates.

 

In my language i need the string: "2 days ago" written this way:

"ago 2 days".

 

Is there a way to do it in my theme?

 

 

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Dec 31, 2013 - 6:08 am

Now that is a real good question and the answer is no. But it can quite easily be yes i think.

Let me have a quick play but I propose that we can add a filter to the code that you can then easily use to change the display characteristics. And we should be able to do that right away.

I ill get back to you after I work it out...

andy-signature.png
YELLOW
SWORDFISH
Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Dec 31, 2013 - 6:49 am

OK - what I can do is give you the edits to make to the current code. I will then make sure that the filter gets included in the sp_nicedate() function in the very next update so things will continue to work afterwards.

So - first change is to the sp_nicedate() function in the sp-api-timezone.php file as follows:

Change:

} else {
    return "$difference $periods[$j] {$tense}";
}

at the end of the function... to:

} else {
    $nd = "$difference $periods[$j] {$tense}";
    return apply_filters('sph_nicedate', $nd, $difference, $periods[$j], $tense);
}

and then add the following filter function to your spFunctions.php file - found in the /templates folder of the Simple:Press theme you are using.

add_filter('sph_nicedate', 'my_nicedate', 1, 4);
function my_nicedate($nd, $difference, $period, $tense) {
    return $tense.' '.$difference.' '.$period;
}

and that should give you what you are after I believe.

andy-signature.png
YELLOW
SWORDFISH
Avatar
David H
Member
Free Members
sp_UserOfflineSmall Offline
Dec 31, 2013 - 8:33 am

Great!

Thank you very much.

I did it, and it works perfectly.

 

David

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Dec 31, 2013 - 9:08 am

You're welcome. The filter is a good idea and is already in the next update build.

It will - I should have added - also pick up any translations in force on the site. But perhaps you have already discovered that...

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 620
Members: 17365
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10128
Posts: 79626