Date on comments

Posted in: Newspaper
Post count: 15

Hello!

I want to display the date of the comments as “X hours ago / X days ago” rather than “Month/Day/Year”. In order to do so, I installed the plugin “Time Ago” by MEKS.

However, I get this error message:

date() expects parameter 2 to be integer, string given in /home/alber870/public_html/wp-content/themes/Newspaper/includes/wp_booster/td_module_single_base.php on line 290

Line 290 of the code reads this:

$buffy .= ‘<time class=”entry-date updated td-module-date’ . $visibility_class . ‘” datetime=”‘ . date(DATE_W3C, $td_article_date_unix)

I contacted MEKS regarding this issue and they recommended contacting TagDiv support since they said it has to do with the Newspaper theme and the WordPress standard human_time_diff() function: https://codex.wordpress.org/Function_Reference/human_time_diff.

How can I fix it? Thanks again for your help!

  • This topic was modified 9 years by benitouk.
  • This topic was modified 9 years by benitouk.
Post count: 22421

Hello,

I can’t say for sure about the plugin but since you already have to make modification in the code to make the plugin work, you might as well code the time ago and not use any plugin at all for it. Please use this guide: https://forum.tagdiv.com/topic/changing-the-date-to-x-time-ago/

Thanks.

Post count: 15

For some reason, all the entries show “5 days ago”

What am I doing wrong?

Post count: 15

For some reason, all the entries show “5 days ago”

What am I doing wrong?

Post count: 22421

Hello,
The function presented there is meant for posts, not comments. That is why it will not work properly on comments. You will have to adapt the code in order for it to work properly on comments .
Add this code:
<?php printf( _x( '%s ago', '%s = human-readable time difference', 'your-text-domain' ), human_time_diff( get_comment_time( 'U' ), current_time( 'timestamp' ) ) ); ?>

Like so: https://www.screencast.com/t/EIkDG4cR1

result: https://www.screencast.com/t/kuKy2Kkhv6SF

Thanks.

Post count: 15

Sorry for not explaining properly. I meant to say that all the blog posts showed 5 days ago. Today, all of them, even the new ones say “6 days ago” like this:

This is the code that I have for module 1. Is there something missing?:

<?php

class td_module_1 extends td_module {

function __construct($post) {
//run the parrent constructor
parent::__construct($post);
}

function render() {
ob_start();
?>

<div class="<?php echo $this->get_module_classes();?>">
<div class="td-module-image">
<?php echo $this->get_image('td_324x160');?>
<?php if (td_util::get_option('tds_category_module_1') == 'yes') { echo $this->get_category(); }?>
</div>
<?php echo $this->get_title();?>

<div class="td-module-meta-info">
<?php echo $this->get_author();?>
<?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>
<!-- --><?php //echo $this->get_date():?>
<?php echo $this->get_comments();?>
</div>

<?php echo $this->get_quotes_on_blocks();?>

</div>

<?php return ob_get_clean();
}
}

What am I doing wrong? Thanks again!

Post count: 22421

Hi,
You missed the post_id part from the link I provided

Please use this code:

<?php $post_id = $this->post->ID;?>
<?php echo human_time_diff( get_the_time('U', $post_id), current_time('timestamp') ) . ' ago'; ?>

Thanks.

Post count: 15

Hi Bogdan,

Now I just need to put the word “ago” before the time.

At the moment, it says “X hours ago”, I need to change it to “ago X hours” so it matches my language.

Thanks again!

Post count: 15

Any idea how I can do this? Thanks

Post count: 22421

Simply put ago in front of the function.
<?php $post_id = $this->post->ID;?>
<?php echo 'ago ' . human_time_diff( get_the_time('U', $post_id), current_time('timestamp') ); ?>

  • This reply was modified 9 years by Bogdan B..
Viewing 10 posts - 1 through 10 (of 10 total)
The forum ‘Newspaper’ is closed to new topics and replies.