• Resolved Briesmi

    (@briesmi)


    Hey,

    first of all i want to thank you for that great support.

    I want to change the function “athemes_posted_on” in “template-tags.php”. Actually it displays always the date when the post was created. Thats ok, but if the post is e.g. from today, it shows 2014-10-07 but i want to display Today instead of the date. Same for day before, there should be displayed Yesterday.

    Is this possible?

    Thanks so much from germany!

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

    you can get the human readable time format by using a wordpress function available. human_time_diff

    You can make this changes by redefining the function “athemes_posted_on” in your child theme’s functions.php file.

    function athemes_posted_on() {
    	$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
    	//if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
    		//$time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
    
    	$time_string = sprintf( $time_string,
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( human_time_diff( get_the_date( 'U' ) ) . ' ago' ),
    		esc_attr( get_the_modified_date( 'c' ) ),
    		esc_html( get_the_modified_date() )
    	);
    
    	printf( __( '<span class="posted-on">Posted on %1$s</span><span class="byline"> by %2$s</span>', 'athemes' ),
    		sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
    			esc_url( get_permalink() ),
    			esc_attr( get_the_time() ),
    			$time_string
    		),
    		sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
    			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    			esc_attr( sprintf( __( 'View all posts by %s', 'athemes' ), get_the_author() ) ),
    			esc_html( get_the_author() )
    		)
    	);
    }

    Also i see you have been using verion 3.8.3. I will suggest you to keep your site updated with the latest.

    Thread Starter Briesmi

    (@briesmi)

    Hey Maruti,

    thanks for the help! I will not update wp cause my plugin is not compatible with the latest version.

    To the function:

    Human time is a good idea! But its not perfect.. I want to echo “today” only if the post was created within the same day, and “yesterday” if the post was created a day before. For all posts >2 days should displayed the normal date format. Is this possible, too?

    Thank you so much!

    Hi Briesmi,

    This is definitely possible but you will have to built up a custom function for this.

    You can take reference form how Human time diff works.

    Thanks

    Hi Briesmi,

    In case you haven’t figured out the custom function, you can use the below in your child theme’s functions.php file

    function heiro_human_time_diff( $timestamp ) {
    	$date = date('Y-m-d', $timestamp);
    	$today = date('Y-m-d');
    	$yesterday = date('Y-m-d', strtotime('yesterday')); 
    
    	// Checking the status
    	if ( $date == $today )
    		$status = 'Today';
    	else if ( $date == $yesterday )
    		$status = 'Yesterday';
    	else
    		$status = get_the_date();
    
    	return $status;
    }

    and in the athemes_posted_on function, replace human_time_diff which I suggested earlier with the custom function heiro_human_time_diff

    so it looks like the following

    $time_string = sprintf( $time_string,
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( heiro_human_time_diff( get_the_date('U') ) ),
    		esc_attr( get_the_modified_date( 'c' ) ),
    		esc_html( get_the_modified_date() )
    	);

    Hope it helps

    Thanks

    Thread Starter Briesmi

    (@briesmi)

    Maruti,

    sorry for the late answer…

    But you are my hero ??

    It works!!

    There was some mistakes, i replaced heiro with hiero, and now it works.

    Just a last thing:

    Is there a way to display featured posts with tomorrow? I got a pluin for football fixtures, to display the match day.
    Thank you so much !!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Change "function athemes_posted_on"’ is closed to new replies.