
Basically what I am hoping to accomplish is this:
1) Nothing displays on the page at first except the row of Years
2) User clicks on year and it loads the associated months in that row
3) User clicks on specific month and it loads the posts below in that area
I am having a hell of a time trying to figure out how best to accomplish this, any ideas to help point me in the right direction would be greatly appreciated.
<?php
/*
Template Name: Custom Archives
*/
?>
<?php get_header(); ?>
<div id="archive-wrap">
<h1 class="left">Blog: Archives</h1>
<h2 class="right"><a href="<?php bloginfo('url'); ?>/blog" title="Latest Posts" id="back-to-posts">Latest Posts</a></h2>
<div id="archive">
<div id="archive-list">
<div id="archive-year">
<h2 class="left">Select a Year</h2>
<ul class="left">
<?php
$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC");
foreach($years as $year):
?>
<li><a href="<?php echo get_year_link($year); ?>" title="<?php echo $year; ?>"><?php echo $year; ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<div id="archive-months">
<ul>
<?php
$months = $wpdb->get_col("SELECT DISTINCT MONTH(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND YEAR(post_date) = '".$year."' ORDER BY post_date DESC");
foreach($months as $month):
?>
<li><a href="<?php echo get_month_link($year, $month); ?>"><?php echo date('F', mktime(0, 0, 0, $month)); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<div id="archive-results">
<div id="archives-found" class="left">
<?php
//Query Posts by Year and Month Selected
$monthly_posts = query_posts("cat=1&year=".$year."&monthnum=".$month."&order=DESC");
//Count Returned Posts
$post_count = count($monthly_posts);
?>
<h3>
<?php
if($post_count == 1)
{
echo $post_count.' blog post found';
} else
{
echo $post_count.' blog posts found';
}
?>
</h3>
</div>
<div id="archive-posts" class="left">
<ul>
<?php
//If Posts Exist Display in List
if(have_posts()): while(have_posts()) : the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
//End Post Loop
endwhile;
//End Post IF
endif;
wp_reset_query();
?>
</ul>
</div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>