Title: Adding a line break within PHP code
Last modified: August 21, 2016

---

# Adding a line break within PHP code

 *  [DJCopa](https://wordpress.org/support/users/djcopa/)
 * (@djcopa)
 * [13 years ago](https://wordpress.org/support/topic/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)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years ago](https://wordpress.org/support/topic/adding-a-line-break-within-php-code/#post-3750589)
 * This would be best accomplished using CSS – possibly by adding a margin top to
   the `<h3>` heading for each month or a margin-bottom to `ul.archive-list`.
 *  Thread Starter [DJCopa](https://wordpress.org/support/users/djcopa/)
 * (@djcopa)
 * [13 years ago](https://wordpress.org/support/topic/adding-a-line-break-within-php-code/#post-3750778)
 * Hi esmi – thanks for taking the time to reply.
    Your comment makes sense so will
   see what I can do with my limited knowledge (although learning all the time!).
 * Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Adding a line break within PHP code’ is closed to new replies.

## Tags

 * [line-break](https://wordpress.org/support/topic-tag/line-break/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [sidebar](https://wordpress.org/support/topic-tag/sidebar/)

 * 2 replies
 * 2 participants
 * Last reply from: [DJCopa](https://wordpress.org/support/users/djcopa/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/adding-a-line-break-within-php-code/#post-3750778)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
