Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In a loop, I want to display "Yesterday" if the date of the post(s) are dated from yesterday...

So here it goes:

<?php
    if( date('Yz') == get_the_time('Yz') ) {
        echo 'Today';
    } elseif ( date('') == get_the_time('') ) {
        echo  'Yesterday';
    } else {
        the_date();
    };
?>

Would you guys know the correct syntax on the elseif line?

Best regards, Alex


Well, I can't answer my question yet because I'm a noob (not enough reputation). So here it is:

<?php $w_h = $w_d = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php
    if ( date('Yz') == get_the_time('Yz') ) {
        if (!$w_d++) echo 'Today<br />';
    } elseif ( date('Yz')-1 == get_the_time('Yz') ) {
        if (!$w_h++) echo 'Yesterday<br />';
    } else {
        echo the_date();
    };
?>
share|improve this question
    
I've added a community wiki version of your solution that you can accept so that the question is considered answered :) –  Edd Nov 22 '11 at 16:41
    
THank you. Did it. –  flintsburg Nov 22 '11 at 16:44
add comment

1 Answer

up vote 1 down vote accepted

As you discovered, one possible solution is something like:

<?php $w_h = $w_d = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php
    if ( date('Yz') == get_the_time('Yz') ) {
        if (!$w_d++) echo 'Today<br />';
    } elseif ( date('Yz')-1 == get_the_time('Yz') ) {
        if (!$w_h++) echo 'Yesterday<br />';
    } else {
        echo the_date();
    };
?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.