• Resolved mehmeh

    (@mehmeh)


    Hello,

    Thanks for this plugin. I was wondering if it’d be possible to format the time as; “X minutes ago, X hours ago, X days ago” and so on, instead of the formal PHP time format. If someone left a comment 2 minutes ago, writing i.e. 2 minutes ago, is much better than writing 8 Mar 2018, 22:34.

    I’d think this would be fairly easy to implement for a dev, no?

    Thank you

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi,

    Sorry for the slow reply. You could do this but you would need to implement a ‘relative date/time’ function as there aren’t any natively in PHP. This forum thread gives some examples: https://stackoverflow.com/questions/2690504/php-producing-relative-date-time-from-timestamps

    In our plugin you would then need to override the call to get_comment_date() function in Better_Recent_Comments_Util::get_recent_comments(), either directly, or using the ‘get_comment_date’ filter.

    Andy

    I would like to do something a little simpler than changing to relative time. Alas, I only know enough about coding to get myself in trouble. I tried adding the following to my theme’s functions file, but (aside from the fact that it’s quite unwieldy) it didn’t work at all.

    
    /*...............
    Changing  date format from 'M j, H:i' to 'l, j F Y' on Better_Recent_Comments_Util
    ...............*/
    	function new_default_shortcode_args() {
    		return array(
    			'number'		 => 5,
    			'format'		 => self::get_comment_format(),
    			'date_format'	 => 'l, j F Y',
    			'avatar_size'	 => 50,
    			'post_status'	 => 'publish',
    			'excerpts'		 => true
    		);
    	}
    	add_filter('default_shortcode_args', 'new_default_shortcode_args');

    The description of the plugin implies that the date format can be changed in the shortcode

    Options available with the shortcode:
    […] date_format – the PHP date format to use. Defaults to ‘M j, H:i’. See this cheat sheet for a full list of date and time options.

    Rather than imposing an arbitrary date format, please explain how to change the coding to use the date format that is in the WP settings: date(get_option('date_format'))

    If I knew how to do this, I would…. Thank you for any help that can be offered on this.

    E Morris

    Hi,

    It’s not possible currently to default to the WordPress date format setting. However you could pass the same date format you have set there into the shortcode, by setting the date_format option. For example:

    [better_recent_comments date_format="l, j F Y"]

    Andy

    Thank you, Andy. Because I’m using the sidebar widget, I had hoped it could be incorporated into the coding itself, but at least this is a solution. I’ll keep staring at the coding to see where to put the shortcode. I wonder if I can do this in my theme’s functions file with a conditional. Something along the lines of “if better-recent-comments is there… then date_format=”l, j F Y” (Again, having attended the University of the Internet, I only know enough about coding to get myself in trouble.)

    Do you think that setting the default to the WP date format setting might be an option in a future version? I hope so….

    E Morris

    A little knowledge is a dangerous thing

    Hi,

    I don’t think you need to add any code. If you add a new text widget under Appearance -> Widgets, then paste the shortcode I included earlier, that should do it…

    All being well ??

    Ohhhh! I hadn’t thought of that option. But, alas, it didn’t work. The date format remained in the M j, H:i form. Also, there was no way to make the comments themselves invisible. I only want the commenter’s name, post link and comment date to show on the sidebar.

    Also, the text version was shifted over to the right (I confess that I didn’t look at the rendered coding to see what was causing it (an extra <ul><li> perhaps??)

    So. I guess I will have to live with the existing date format.

    Excuse me for replying to myself….

    Success!!

    I reread the format instructions at https://www.ads-software.com/plugins/better-recent-comments/ and, at last, this line of code put into a Widget text produces the date format that is the same as on my WP.

    [better_recent_comments format="{author} on {post}, {date}" date_format="l, j F Y"]

    I did have to fool around a bit with the css because the text file throws things over to the right a bit.

    These are the styles that I put into my theme’s style sheet:

    /* Better recent Comments */
    #better-recent-comments li {background:transparent url('/images/customicon.gif') no-repeat left 6%; padding-left:15px;}
    #better-recent-comments li .comment-date {display:inline;}
    #better-recent-comments li .comment-date::before {content:" on  ";}
    #better-recent-comments .recent-comment {margin-left:-6px;}

    Thank you again for your assistance, Andy.

    -E Morris

    Hi,

    Great!! Glad you got it working. And thanks for the review. We’ll definitely look at adding more examples and generally improving the documentation as it is a bit ‘thin’.

    Cheers,
    Andy

    Thank you for all your help, Andy.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Date format’ is closed to new replies.