Title: Undefined offset
Last modified: August 30, 2016

---

# Undefined offset

 *  Resolved [misharnet](https://wordpress.org/support/users/misharnet/)
 * (@misharnet)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/undefined-offset-11/)
 * I am trying to adjust WordPress core Archives Widget so it appears as a nice 
   looking drop down menu. I did it and it works, but when wp_debug is set to true
   it shows the following Notice: Undefined offset: 1 in C:\xampp…
 * it is in this code:
 *     ```
       <?php
       		/**
       		 * Filter the arguments for the Archives widget.
       		 *
       		 * @since 2.8.0
       		 *
       		 * @see wp_get_archives()
       		 *
       		 * @param array $args An array of Archives option arguments.
       		 */
       		$archives = strip_tags(wp_get_archives( apply_filters( 'nsgen_archive_widgets_args', array(
       			'type'            => 'monthly',
       			'format'          => 'custom',
       			'echo'            => 0,
       			'after'           => ','
       		) ) ) );
       		$archives = explode(',', $archives);
       		$months = array();
       		$years = array();
       		// Grab our years first
       		foreach ($archives as $archive) {
       			$archive = explode(' ', $archive);
       			if (isset($archive[1])) {
       				array_push($years, $archive[1]);
       			}
       		}
       		$years = array_values(array_unique($years));
       		$i = 0;
       		foreach ($years as $year) {
       		?><li class="nsgen-archive-year"><a><?php
       			echo $year;
       			?></a><ul><?php
       			foreach ($archives as $archive) {
       				$archive = explode(' ', $archive);
                                          if ($archive[1] == $year) {
       					echo '<li class="nsgen-archive-month"><a href="' .
       					// Get the archive link
       					get_month_link($year, date("m", strtotime($archive[0] . '-' . $year))) .
       					'">' . trim($archive[0]) . '</a></li>';
             			}
       			}
       			?></ul><?php
       		?></li><?php
       		}
       ?>
       ```
   
 * this part: if ($archive[1] == $year) {
    Can some one help, please.

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

 *  [Dion](https://wordpress.org/support/users/diondesigns/)
 * (@diondesigns)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/undefined-offset-11/#post-6306863)
 * If you change this line:
 *     ```
       if ($archive[1] == $year) {
       ```
   
 * to this:
 *     ```
       if (isset($archive[1]) && $archive[1] == $year) {
       ```
   
 * the error should disappear.
 *  Thread Starter [misharnet](https://wordpress.org/support/users/misharnet/)
 * (@misharnet)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/undefined-offset-11/#post-6306885)
 * Thanks DionDesigns it works!

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

The topic ‘Undefined offset’ is closed to new replies.

## Tags

 * [undefined offset](https://wordpress.org/support/topic-tag/undefined-offset/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [misharnet](https://wordpress.org/support/users/misharnet/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/undefined-offset-11/#post-6306885)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
