Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do I add timestamp to posts within a topic?

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

  • Robin W
    Moderator

    @robin-w

    not quite sure what you are after, can you explain further ?


    Majijiboo
    Participant

    @majid436


    Robin W
    Moderator

    @robin-w

    basically you’d need to cut some code to display the date/time, put it in a function that echo’s it, and then hook it to the following action

    add_action (‘bbp_theme_before_reply_content’, ‘your_function’) ;

    see

    Step by step guide to setting up a bbPress forum – part 4

    sorry am up to my armpits in other code, or I’d cut it for you !


    Majijiboo
    Participant

    @majid436

    Thanks for responding. I made the below code and unfortunately didn’t work. When you have time in a week or 2, would love to know what went wrong. Thanks.

    function post_time ( $output) {
    $output = preg_replace( '/, .*[^ago]/', ' ', $output );
    echo $output;
    }
    add_action ('bbp_theme_before_reply_content', 'post_time') ;

    Robin W
    Moderator

    @robin-w

    Have made a note to come back to this !


    tharsheblows
    Participant

    @tharsheblows

    You can use bbp_reply_post_date for it – it will give you “August 4, 2012 at 2:37 pm”. I mean, it would give you that for posts on Aug 4, 2012 at 2.37pm and similar things for other dates.

    But you want to style it a bit, so something like:

    function mjj_post_reply_date(){
      printf('<div class="mjj-post-date">');
      bbp_reply_post_date(); 
      printf('</div>');
    }
    
    add_action ('bbp_theme_before_reply_content', 'mjj_post_reply_date') ;

    Majijiboo
    Participant

    @majid436

    Thanks. It works. Is there a way to only show the date and not the hour/minute? Maybe using code similar to the below could help?

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

    tharsheblows
    Participant

    @tharsheblows

    Yep – use get_post_time() – https://codex.wordpress.org/Template_Tags/get_post_time

    function mjj_post_reply_date(){
      printf('<div class="mjj-post-date">');
      $reply_id = bbp_get_reply_id( $reply_id );
      printf( get_post_time( get_option( 'date_format' ), false, $reply_id, true ) ); 
      printf('</div>');
    }
    
    add_action ('bbp_theme_before_reply_content', 'mjj_post_reply_date') ;

    Majijiboo
    Participant

    @majid436

    It worked. Thanks.


    Robin W
    Moderator

    @robin-w

    glad you’re fixed !

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