• aydincavadli

    (@aydincavadli)


    Hi! Please help me! How can i coding latest posts list by date for news website?

    Example:
    Today – 14.11.2014

    • Lorem ipsum dolorem.
    • Lorem ipsum dolorem.
    • Lorem ipsum dolorem.
    • Lorem ipsum dolorem.

    Yesterday – 13.11.2014

    • Lorem ipsum dolorem.
    • Lorem ipsum dolorem.
    • Lorem ipsum dolorem.
    • Lorem ipsum dolorem.
    • Lorem ipsum dolorem.
    • Lorem ipsum dolorem.

    I wrote this code,but every time by changing of date from 31 to 1’st of new month,yesterdays and todays articles are mixed ??

    <div class="current-date"><?php echo date_i18n('j F', time()); ?></div>
    <?php
    $today = getdate();
    $the_query = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"] );
    
    // The Loop
    if ( $the_query->have_posts() ) {
            echo '<ul>';
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
    		echo '<li>';
    		echo '<span class="cur-date">' . get_the_time() . '</span>';
    		echo '<a href="' . get_the_permalink() . '" class="cur-link">' . get_the_title() . '</a>';
    		echo '</li>';
    	}
            echo '</ul>';
    } else {
    	echo '<p style="padding:10px;">';
    	echo 'No posts.';
    		echo '</p>';
    }
    /* Restore original Post Data */
    wp_reset_postdata();?>
    
    <div class="current-date"><?php echo date_i18n("j F", time() - 60 * 60 * 24);?></div>
    <?php
    $yesterday = getdate(time() - 60 * 60 * 24);
    $the_query = new WP_Query( 'year=' . $yesterday["year"] . '&monthnum=' . $yesterday["mon"] . '&day=' . $yesterday["mday"] );
    
    // The Loop
    if ( $the_query->have_posts() ) {
            echo '<ul>';
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
    		echo '<li>';
    		echo '<span class="cur-date">' . get_the_time() . '</span>';
    		echo '<a href="' . get_the_permalink() . '" class="cur-link">' . get_the_title() . '</a>';
    		echo '</li>';
    	}
            echo '</ul>';
    } else {
    	echo '<p style="padding:10px;">';
    	echo 'No posts.';
    		echo '</p>';
    }
    /* Restore original Post Data */
    wp_reset_postdata();?>
  • The topic ‘Last Post By Date (for News website)’ is closed to new replies.