• Resolved ousmanemariko

    (@ousmanemariko)


    I’m trying to get the date to show like it does on here: loopinsight.com. Basically the site shows the current date at the top of the page and if you scroll down, the date is shows when the posts were published on a previous date until another day shows up.

    I know I need a date-container in my style.css file. I know how to do that, but I don’t know how to do it in the php file.

Viewing 9 replies - 16 through 24 (of 24 total)
  • Thread Starter ousmanemariko

    (@ousmanemariko)

    It’s now showing the first date at the top of the page. Now all I need is to get it to the rest.

    I’m not good enough at php to even modify the code, but I’ll see what I can do. Thanks for the help.

    No problem!

    Are you sure that the posts you’re testing with were actually made on different days?

    Thread Starter ousmanemariko

    (@ousmanemariko)

    Yea. I just put a test post up now. The leading date changed, but the previous date didn’t move down with the last post.

    Thread Starter ousmanemariko

    (@ousmanemariko)

    I’m probably doing something wrong. Not sure what..

    Oh, I bet you’re not ordering by post date descending. Add this code *right before* you begin the loop. I’ll leave the before and after lines in tact so that you know exactly where to place it.

    $datetime = null;
    // the following lines are new
    global $query_string;
    query_posts( $query_string . '&orderby=date&order=DESC' );
    // end new lines
    if ( have_posts() ) : while ( have_posts() ) : the_post();

    Since you’re using query_posts to alter the query, you may also wish to reset it after the loop:

    <?php endwhile; ?>
    
    		<?php else: ?>
    
    			<?php get_template_part( 'loop-error' ); // Loads the loop-error.php template. ?>
    
    		<?php endif; ?>
    		<?php
    
    		// the following lines are new
    		rewind_posts();
    		wp_reset_query();
    		// end new lines
    
    		?>
    Thread Starter ousmanemariko

    (@ousmanemariko)

    Still a no-go. :/

    Wait… >.> I feel so stupid!! If the dates are descending then of course post dates won’t get larger…they’ll get smaller!!!

    Change the comparison operator to less-than hehe.

    This:

    } else if ( (int) get_the_time( 'Ymd' ) > $datetime ) {

    to this:

    } else if ( (int) get_the_time( 'Ymd' ) < $datetime ) {

    I so hope this works!

    Thread Starter ousmanemariko

    (@ousmanemariko)

    Holy crap. It works! Thank you SO much. I really appreciate your help.

    Yay 🙂 So glad I could help! Take care!

Viewing 9 replies - 16 through 24 (of 24 total)

The topic ‘Dynamic date?’ is closed to new replies.