Advertisement
Guest User

WP Post By Year

a guest
Sep 6th, 2011
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. <?php
  2.     function edge_subcat_posts_monthly($curr_post, $curr_cat) {
  3.     global $post;
  4.     $ul_open = false;
  5.     $previous_year = 0;
  6.        
  7.     $args=array(
  8.       'cat'     => $curr_cat,
  9.       'posts_per_page' => -1,
  10.       'orderby' => 'date',
  11.       'order' => 'DESC',
  12.       'caller_get_posts'=>1
  13.     );
  14.  
  15.     $my_query = new WP_Query($args);
  16.    
  17.     echo '<ul>';
  18.     if( $my_query->have_posts() ) {
  19.       $ymdate = '';
  20.          
  21.        while ($my_query->have_posts()) : $my_query->the_post();
  22.          
  23.         $year = mysql2date("Y", $post->post_date);
  24.  
  25.         if ( $previous_year != $year) {
  26.             if($ul_open == true){
  27.                 echo '</ul><div class="clear"></div>';
  28.                 }          
  29.        
  30.                         echo '<li><div class="clear"></div><h4 id="cat-'.$year.'">'.$year.'</h4><ul id="posts-'.$year.'" >';
  31.                
  32.                 $ul_open = true;
  33.              }
  34.              $previous_year = $year;             
  35.             ?>
  36.                 <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" <?php if($curr_post == $post->ID){ echo 'class="active"'; } ?>><?php the_title(); ?></a></li>
  37.             <?php
  38.            
  39.           endwhile;
  40.           echo '</ul><div class="clear"></div>';
  41.          
  42.         }
  43.         echo '</ul>';
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement