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 10 replies - 1 through 10 (of 10 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
    Moderator

    @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”!.

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