Skip to:
Content
Pages
Categories
Search
Top
Bottom

Change forum date output


  • Babblebey
    Participant

    @babblebey

    bbp_topic_post_date() & bbp_reply_post_date() returns date in this format September 2, 2018 at 4:34 am.

    How does one change it to the other formats:

    time ago, September 2, 2018 or 2-10-2019

    And possibly other formats as preferred.

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

  • Robin W
    Moderator

    @robin-w

    dashboard>settings>general>date format

    bbpress just follows the WordPress format you set, as it presumes you want dates to look the same all over your site

    otherwise

    bbp style pack

    once activated go to

    dashboard>settings>bbp style pack>Freshness Display lets you play with how it is displayed


    Babblebey
    Participant

    @babblebey

    The Plugin is kind of disturbing my function in the way I have set them up already… And it only works on the Freshness Display, it doesn’t work on the topics and reply post dates.

    I want one that can work similarly like the WordPress the_date('d M, Y') to look like bbp_topic_post_date('d M, Y') to dictate the exact date format I want for that function to return. I do not really want plugins, I’m trying to build with little to no plugins at all.


    Robin W
    Moderator

    @robin-w

    ok looks like you are going to need to get familiar with the templates and some coding then

    In essence you need to copy some templates across to your child theme, and then amend them

    You can copy all the templates across, but you only need to copy those that you want to change, and it is better just to do this, as then you know which you have altered.

    so if you wanted to amend loop-single-forum you would do the following

    create a directory on your theme called ‘bbpress’
    ie wp-content/themes/%your-theme-name%/bbpress

    where %your-theme-name% is the name of your theme

    find
    wp-content/plugins/bbpress/templates/default/bbpress/loop-single-forum.php
    Make a copy of this file, and put in in the directory called bbpress that you created above, so you end up with
    wp-content/themes/%your-theme-name%/bbpress/loop-single-forum.php
    bbPress will now use this template instead of the original
    and you can amend this


    Babblebey
    Participant

    @babblebey

    I have been doing that from the start of the whole process of the project, I have all the bbpress templates copied over to my theme directory, I am doing an edit on exactly all the template.

    But the bbp_topic_post_date('d M, Y') doesn’t work is the thing.


    Robin W
    Moderator

    @robin-w

    ok, how familiar with adding filters are you ?


    Babblebey
    Participant

    @babblebey

    Not very much, I feel very lazy to read this page – https://codex.bbpress.org/step-by-step-guide-to-setting-up-a-bbpress-forum-part-5/

    Aww


    Robin W
    Moderator

    @robin-w

    ok, the existing function is

    function bbp_get_topic_post_date( $topic_id = 0, $humanize = false, $gmt = false ) {
    		$topic_id = bbp_get_topic_id( $topic_id );
    
    		// 4 days, 4 hours ago
    		if ( !empty( $humanize ) ) {
    			$gmt_s  = !empty( $gmt ) ? 'U' : 'G';
    			$date   = get_post_time( $gmt_s, $gmt, $topic_id );
    			$time   = false; // For filter below
    			$result = bbp_get_time_since( $date );
    
    		// August 4, 2012 at 2:37 pm
    		} else {
    			$date   = get_post_time( get_option( 'date_format' ), $gmt, $topic_id, true );
    			$time   = get_post_time( get_option( 'time_format' ), $gmt, $topic_id, true );
    			$result = sprintf( _x( '%1$s at %2$s', 'date at time', 'bbpress' ), $date, $time );
    		}
    
    		return apply_filters( 'bbp_get_topic_post_date', $result, $topic_id, $humanize, $gmt, $date, $time );
    	}

    so we can filter this as follows :

    add_filter ('bbp_get_topic_post_date' , 'rew_date' , 10 , 6) ;
    
    function rew_date ($result, $topic_id, $humanize, $gmt, $date, $time) {
    	$result = 'hello' ;
    
    return $result ;
    }

    This should then say ‘hello’ so all we want to do is change $result to read whatever you want – so what do you want it to say ?

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