November 22, 201214 yr Ok, So I found an example of a simple slider function that displays a list of blog archives by year, when clicked it slides down to show the months of that year. Great! Only problem is that clicking again should hide it, but it doesn't. Any ideas what I am missing? Code below. <script type="text/javascript"> $(document).ready(function() { $('.blog-list-archive li ul').hide(); $('.blog-list-archive li a').click(function(){ $(this).parent().addClass('selected'); $(this).parent().children('ul').slideDown(250); $(this).parent().siblings().children('ul').slideUp(250); $(this).parent().siblings().removeClass('selected'); }); }); </script> <style> .archive-sub-menu { display:none; } </style> <div class="blog-list-archive"> <?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 class="title" href="Javascript:void()"><?php echo $year; ?></a> <ul class="archive-sub-menu"> <? $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> </li> <?php endforeach; ?> </div>
November 22, 201214 yr Author Ok, so after changing the date on a few posts to last year (to bring up a secondary year level) it is actually working lol. However, could this be modified so somehow you can view the archive by year as well, not just have the year selector open the dropdown? Make sense?
Create an account or sign in to comment