Adding a line break within PHP code
-
Hi All,
I’ve setup a custom sidebar for my posts, to try and show the archive using the code below (archive is referenced from index.php, if it matters). Works OK, but struggling to put a space after the last month of a year, and the next year to make it look tidy. I’ve tried all sorts, but my knowledge is limited – Any suggestions would be great.
Thanks,
Darren.
p.s – This is all on my localhost copy at the mo, so can’t show how the sidebar looks – sorry.
<h3>Archives</h3> <?php $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 = 'post' GROUP BY month , year ORDER BY post_date DESC"); foreach($months as $month) : $year_current = $month->year; if ($year_current != $year_prev){ if ($year_prev != null){?> </ul> <?php } ?> <h3><?php echo $month->year; ?></h3> <ul class="archive-list"> <?php } ?> <li> <a href="<?php bloginfo('url') ?>/<?php echo $month->year; ?>/<?php echo date("m", mktime(0, 0, 0, $month->month, 1, $month->year)) ?>"> <span class="archive-month"><?php echo date("F", mktime(0, 0, 0, $month->month, 1, $month->year))?></span> <span class="archive-count"><?php echo $month->post_count; ?></span> </a> </li> <?php $year_prev = $year_current; endforeach; ?> </ul>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Adding a line break within PHP code’ is closed to new replies.