custom archive page
-
Hi,
I’ve managed to slightly adapt some code that I’ve found on the web to display yearly/monthly archive of my custom post type (‘news’):
2019 December (3) November (1) 2018 December (5) September (6)
When you click on any of those it’ll take you to domain.com/news/2019 or domain.com/news/2019/12 archives.
I’m not having much luck with adding the ul/li markup in between the php code. Could you have a look at the code below and advise? Thank you
<?php global $wpdb; $limit = 0; $year_prev = null; $months = $wpdb->get_results("SELECT DISTINCT MONTH( post_date ) AS month , YEAR( post_date ) AS year, COUNT( id ) as post_count FROM $wpdb->posts WHERE post_status = 'publish' and post_date <= now( ) and post_type = 'news' GROUP BY month , year ORDER BY post_date DESC"); ?> <div class="menu"> <?php foreach($months as $month) : $year_current = $month->year; if ($year_current != $year_prev){ if ($year_prev != null){?> <?php } ?> <ul> <li><a href="<?php bloginfo('url') ?>/news/<?php echo $month->year; ?>/"><?php echo $month->year; ?></a> <ul> <?php } ?> <li><a href="<?php bloginfo('url') ?>/news/<?php echo $month->year; ?>/<?php echo date("m", mktime(0, 0, 0, $month->month, 1, $month->year)) ?>"><span class="archive-month"><?php echo date_i18n("F", mktime(0, 0, 0, $month->month, 1, $month->year)) ?> (<?php echo $month->post_count; ?>)</span></a></li> <?php $year_prev = $year_current; ?> </ul> </li> <?php endforeach; ?> </ul> </div>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘custom archive page’ is closed to new replies.