• Hey guys, so what i’m trying to do seems simple enough i just can’t find any info on how to do it. I’m using the_date() to format my archives page and it displays the month and year for each post but skips posts that are on the same day. What i need it to do is post the month and year and skip posts that are in the same month instead.

    so it will be:
    September 2012
    28th – post title
    12th – post title
    August 2012
    18th – post title
    12th – post title

    etc, etc.

    Right now it’s doing this:
    September 2012
    28th – post title
    28th – post title
    September 2012
    12th – post title
    August 2012
    18th – post title
    August 2012
    12th – post title

    any help is much appreciated. my code is below

    <?php
    	$args = array( 'numberposts' => 6, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
    			$postslist = get_posts( $args );?>
    
    			<ul>
    			<?php foreach ($postslist as $post) : setup_postdata($post); ?>			   
    
    				<span class="date"><?php the_date('F Y'); ?></span><br />
    
        	        <li><span class="day"><?php the_time('jS')?> - </span><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    
    <?php endforeach; ?>

Viewing 1 replies (of 1 total)
  • This is untested, but I think it is what you want:

    <?php
    $args = array( 'numberposts' => 6, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
    $postslist = get_posts( $args );?>
    
    <ul>
       <?php $prev_mo_yr = '';
       foreach ($postslist as $post) : setup_postdata($post);
          $this_mo_yr = get_the_date('F Y');
          if ( $prev_mo_yr != $this_mo_yr ) { ?>
             <span class="date"><?php echo $this_mo_yr; ?></span><br />
             <?php $prev_mo_yr = $this_mo_yr;
          } ?>
          <li><span class="day"><?php the_time('jS')?> - </span><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
       <?php endforeach; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘the_time() alteration’ is closed to new replies.