Time ago in modules

Posted in: Newsmag
Post count: 28

Hi,

I have edited the functions to make use of the ‘time ago’ feature rather than a standard date format. I was successful in editing the comments to use <?php echo time_ago(); ?> and it works great.

However, I tried modifying the module files, but no changes take effect. Even if I delete the date section completely it will still show. How can I edit the modules and make it show the time ago?

Thanks,

Post count: 28

Sorry, I meant block. For example, I wan to edito block 12. Where is this located?

Thanks,

Post count: 28

Nevermind, I figured it out. Seems the block numbering is different than its module, which made me confused lol

Post count: 28

Ok, so I attempted to use WordPress own variation:

<?php echo human_time_diff( get_the_time(‘U’), current_time(‘timestamp’) ) . ‘ ago’; ?>

In place of the traditional module <?php echo $this->get_date();?> script.

The time ago timestamp gave a very wonky date. An article written today showed it as being ‘2 years ago’, which is obviously incorrect.

Any idea how I could get the time ago functioning on the modules instead of date?

Thanks!

Post count: 62

Strange, should be working.. :S

Do get_date() and current_time(‘timestamp’) give you the correct date when you create a post?

Try to find the error by adding this to your php file:

echo '<script type="text/javascript">alert("' . get_date() . '")</script>';
echo '<script type="text/javascript">alert("' . current_time('timestamp') . '")</script>';

This will show a message box with the return value of both methods…

Post count: 28

This works properly on the actual post page. However, it does not work in the meta section of the post when being shown via module block.

Any idea why the module would be showing incorrectly? Posts shown through the module from 2014 say ’45 years ago’ lol.

Thanks,

Post count: 62

Ok, I think I know how to solve this problem. I will test it and return it to you.

Post count: 62

I think you put this code:

<?php echo human_time_diff( get_the_time(‘U’), current_time(‘timestamp’) ) . ‘ ago'; ?>

inside Newsmag/includes/modules/[YOUR MODULE].php

instead of putting it inside get_date() in:

Newsmag/includes/wp-booster/td_module.php

Am I right?

Post count: 28

Unfortunately, I originally tried that by editing block 14’s module. That’s how I get the odd timing.

Any other suggestions?

Thanks!

Post count: 62

I’m gonna try it on my own site..

Post count: 62

Ok, I have tested it…

Put this:

human_time_diff( $td_article_date_unix, (int) current_time(‘timestamp’))

In the get_date() method inside /includes/wp_booster/td_module.php

My get_date() method inside td_module.php:

Don’t copy/paste the example, because it could change operations, since I’ve customized a lot in my theme!)

function get_date($show_stars_on_review = true) {
        $visibility_class = '';
        if (td_util::get_option('tds_p_show_date') == 'hide') {
            $visibility_class = ' td-visibility-hidden';
        }

        $buffy = '';
        if (td_review::has_review($this->td_review) and $show_stars_on_review === true) {
            //if review show stars
            $buffy .= '<div class="entry-review-stars">';
            $buffy .=  td_review::render_stars($this->td_review);
            $buffy .= '</div>';

        } else {
            if (td_util::get_option('tds_p_show_date') != 'hide') {
                $td_article_date_unix = get_the_time('U', $this->post->ID);
                $buffy .= '<div class="td-post-date">';
                    $buffy .= '<time  itemprop="dateCreated" class="entry-date updated td-module-date' . $visibility_class . '" datetime="' . date(DATE_W3C, $td_article_date_unix) . '" > ' . human_time_diff( $td_article_date_unix, (int) current_time(‘timestamp’)) . '</time>';
                    $buffy .= '<meta itemprop="interactionCount" content="UserComments:' . get_comments_number($this->post->ID) . '"/>';
                $buffy .= '</div>';
            }
        }

        return $buffy;
    }
Post count: 28

Legend! Got it working. Thanks a bunch!

Post count: 62

No problem, have fun!

Viewing 13 posts - 1 through 13 (of 13 total)
The forum ‘Newsmag’ is closed to new topics and replies.