Advertisement
deeve

menu query

May 18th, 2012
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. <?php
  2.         $y = date( 'Y' ); // The current year.
  3.         while ( $y > 2007 ) { // Pick a reasonable year you want this loop to end at, to save your server some time.
  4.             $m = 12; // For December
  5.             while ( $m > 0 ) {
  6.                 $args = array(
  7.                     'posts_per_page' => -1,
  8.                     'cat'        => 7,
  9.                     'year'       => $y,
  10.                     'monthnum'   => $m
  11.                 );
  12.                 $cat_q = new WP_Query( $args );
  13.                 if ( $cat_q->have_posts() ) {
  14.                     $p = 0;
  15.                     while ( $cat_q->have_posts() ) {
  16.                         $cat_q->the_post();
  17.                         $p++;              
  18.                     }
  19.                     $monthName = date( 'F', mktime( 0, 0, 0, $m, 10 ) );
  20.                     ?>
  21.                     <li>
  22.                         <a href="<?php bloginfo( 'url' ); ?>/category-archive?themonth=<?php echo $m; ?>&theyear=<?php echo $y; ?>&cat=7"><?php echo $monthName.' '.$y.'('.$p.')'; ?></a>
  23.                     </li>  
  24.                     <?php
  25.                 }
  26.                 wp_reset_query();
  27.                 $m--;
  28.             }
  29.             $y--;
  30.         }
  31.         ?>
  32.     </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement