Nested year, month and date archive navigation.
-
interesting..
try
get_day_link();
get_month_link();
get_year_link();That could be used if I wanted to cover every single day of every single of every single month of every single year, but I only want to show links for days/months/years that have posts in them.
Surely there is a way?
I did not say you should put it directly,
I said, do a loop function to filter posts, using those hooks to display links.<ul> <?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); ?> "><?php echo $year; ?></a> <ul> <? $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> <ul> <? $days = $wpdb->get_col("SELECT DISTINCT DAY(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND MONTH(post_date) = '".$month."' AND YEAR(post_date) = '".$year."' ORDER BY post_date DESC"); foreach($days as $day) : ?> <li><a href="<?php echo get_day_link($year, $month, $day); ?>"><?php echo $day;?></a></li> <?php endforeach;?> </ul> </li> <?php endforeach;?> </ul> </li> <?php endforeach; ?> </ul>This should do the trick. I was looking for the same answer myself and figured I’d add this up. There may be a more efficient way to do this, but that’s what I used to get it working.
This code is really great, is there a way to add an additional layer with post titles?
- 2008
- January
- 15th
- Post title 1
- Post title 2
- 17th
- Post title 1
- Post title 2
The topic ‘Nested year, month and date archive navigation.’ is closed to new replies.