Skip to:
Content
Pages
Categories
Search
Top
Bottom

Change of date for freshness


  • virusek89
    Participant

    @virusek89

    Hello,

    How to change the date for freshness? I now have this:

    7 hours, 6 minutes ago
    1 day, 5 hours ago
    2 days, 22 hours ago
    1 week, 1 day ago
    2 weeks, 1 day ago
    2 weeks, 3 days ago
    1 month, 1 week ago
    2 months, 1 week ago

    I want to change that showed this:

    7 hours ago
    1 day ago
    2 days ago
    1 week ago
    2 weeks ago
    2 weeks ago
    1 month ago
    2 months ago

    How to do it please help?

    Sorry for my bad english

Viewing 14 replies - 1 through 14 (of 14 total)

  • virusek89
    Participant

    @virusek89

    Is there anyone able to help me?


    Robin W
    Moderator

    @robin-w

    Yes, it’s doable, but I’ve not yet delved into how to do it !


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    You’ll want to filter the output of bbp_get_time_since; it’s the function responsible for humanizing timestamps. You’ll probably want to perform a string replacement starting at the comma, and append your own ‘ago’ at the end.


    virusek89
    Participant

    @virusek89

    bbp_get_time_since

    I found it in these files

    bbpress\includes\topics\template-tags.php
    bbpress\includes\replies\template-tags.php
    bbpress\includes\forums\template-tags.php
    bbpress\includes\common\widgets.php
    bbpress\includes\common\functions.php

    Now what I need to edit to remove the rest of the decimal?

    I want to ask because I am a beginner in php


    Robin W
    Moderator

    @robin-w

    Give me a day or two, and I’ll come back with a more detailed response.


    virusek89
    Participant

    @virusek89

    Ok I’ll wait


    Stephen Edgar
    Keymaster

    @netweb


    Robin W
    Moderator

    @robin-w

    so the answer is

    function short_freshness_time( $output) {
    $output = preg_replace( '/, .*[^ago]/', ' ', $output );
    return $output;
    }
    add_filter( 'bbp_get_time_since', 'short_freshness_time' );
    add_filter('bp_core_time_since', 'short_freshness_time');

    Drop this into your functions file


    virusek89
    Participant

    @virusek89

    @Robin and @Stephen Thank you for your help. Everything works perfectly 🙂


    Robin W
    Moderator

    @robin-w

    Great, glad to hear you’re fixed, and have just added the code to one of my forums. One of those moments when you see something and think “that looks better”!.


    Matthias
    Participant

    @matthias70

    The above code in functions.php works for me, except for “weeks” in german “Wochen”
    Perhaps the regex is wrong, but after Wochen I have an “ag”

    It’s not there in my german language file?
    https://gtauscht.de/forums/
    Do you have any suggestions?

    Thanks
    Matthias


    Matthias
    Participant

    @matthias70

    Just found a solution.
    Don’t know why but a space at the end of Wochen did it.
    Strange that Jahre and Tage don’t need the additional space at the end…?


    Robin W
    Moderator

    @robin-w

    I could dig into it, but as it is working I won’t 🙂 But thanks for posting the answer, if others find the same issue, I’ll look to update.

    Glad you are fixed !!


    neon67
    Participant

    @neon67

    Life-hack for non-English speaking users. There is no need to change anything in the functions.php.
    Just enough to change the translation file, for example, in Loco-translate.
    You translate the hours into your language as it should, and instead the minutes make empty field. Save.

    Its works.

Viewing 14 replies - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.
Skip to toolbar