• Hi there,

    I’ve had such a hard time with this one. I’m trying to adjust this:

    $time_string = ‘<time class=”entry-date published” datetime=”%1$s”>%2$s</time>’;

    to this

    $time_string = ‘<?php echo relative_time(get_the_time(‘U’), current_time(‘timestamp’)) . ‘ ago’; ?>’;

    I’ve got coding in the function.php to grab how long ago the post was posted, but I the theme doesn’t have the template tags very easily done so I can’t simply replace the normal <?php the_time(); ?>

    Let me know if you have any questions. Your help is much appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Hi cjohnson26

    Can you show us the printf or sprintf function that is used with the $time_string variable.

    I’m guessing the relative_time() function is similar to the WordPress human_time_diff() function.
    http://codex.wordpress.org/Function_Reference/human_time_diff

    Thread Starter cjohnson26

    (@cjohnson26)

    Hey keesiemeijer!

    Yeah, it’s a variation of the human_time_diff() – I just changed the name so it wouldn’t clash with the original coding.

    Here’s the full code for that section:

    function themememe_posted_on() {
    $time_string = ‘<time class=”entry-date published” datetime=”%1$s”>%2$s</time>’;

    $time_string = sprintf( $time_string,
    esc_attr( get_the_date( ‘c’ ) ),
    esc_html( get_the_date() ),
    esc_attr( get_the_modified_date( ‘c’ ) ),
    esc_html( get_the_modified_date() )
    );

    printf( __( ‘<span class=”byline”><i class=”fa fa-user”></i>%1$s</span><span class=”posted-on”><i class=”fa fa-calendar”></i>%2$s</span>’, ‘themememe’ ),
    sprintf( ‘<span class=”author vcard”>%2$s</span>’,
    esc_url( get_author_posts_url( get_the_author_meta( ‘ID’ ) ) ),
    esc_html( get_the_author() )
    ),
    sprintf( ‘<!––>%2$s<!––>’,
    esc_url( get_permalink() ),
    $time_string
    )
    );
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Parse error: syntax error, unexpected T_STRING’ is closed to new replies.