Title: Help with loop function code and footer by month
Last modified: August 21, 2016

---

# Help with loop function code and footer by month

 *  Resolved [charldarwin](https://wordpress.org/support/users/charldarwin/)
 * (@charldarwin)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/help-with-loop-function-code-and-footer-by-month/)
 * Hi this is Charls.
    I would like to get help with this please. I’m using this
   code to show content in header and I would like to get help with footer:
 * the-events-calendar\lib\widget-list.class.php
 *     ```
       header_widget();
       tribe_get_template_part( 'widgets/list-widget' );
       footer_widget();
       ```
   
 * for header_widget function is a copy of header function using in the-events-calendar\
   public\template-tags\loop.php
 * This is the function with some modifications:
 *     ```
       function header_widget() {
   
       		/* Month and year separators (on every month and year change) */
   
       		$show_headers = apply_filters( 'tribe_events_list_show_date_headers', true );
   
       		$html = '';
   
       		if ($show_headers) {
   
       			global $post, $wp_query;
   
       			$event_year = tribe_get_start_date( $post, false, 'Y' );
       			$event_month = tribe_get_start_date( $post, false, 'm' );
   
       			if ($wp_query->current_post > 0) {
       				$prev_post = $wp_query->posts[$wp_query->current_post - 1];
       				$prev_event_year = tribe_get_start_date( $prev_post, false, 'Y' );
       				$prev_event_month = tribe_get_start_date( $prev_post, false, 'm' );
       			}
   
       			/*
       			 * If the event month changed since the last event in the loop,
       			 * or is the same month but the year changed.
       			 *
       			 */
       			if ( $wp_query->current_post === 0 || ( $prev_event_month != $event_month || ( $prev_event_month == $event_month && $prev_event_year != $event_year ) ) ) {
       				$html .= sprintf( "<div class='another-month-class'><div style='height: 10px;' class='header-widget-content'>");
       			}
   
       			echo apply_filters('header_widget', $html, $event_month, $event_year);
       		}
       	}
       ```
   
 * This is the original function you used in the plugin
 *     ```
       function tribe_events_list_the_date_headers_widget() {
   
       		/* Month and year separators (on every month and year change) */
   
       		$show_headers = apply_filters( 'tribe_events_list_show_date_headers', true );
   
       		$html = '';
   
       		if ($show_headers) {
   
       			global $post, $wp_query;
   
       			$event_year = tribe_get_start_date( $post, false, 'Y' );
       			$event_month = tribe_get_start_date( $post, false, 'm' );
   
       			if ($wp_query->current_post > 0) {
       				$prev_post = $wp_query->posts[$wp_query->current_post - 1];
       				$prev_event_year = tribe_get_start_date( $prev_post, false, 'Y' );
       				$prev_event_month = tribe_get_start_date( $prev_post, false, 'm' );
       			}
   
       			/*
       			 * If the event month changed since the last event in the loop,
       			 * or is the same month but the year changed.
       			 *
       			 */
       			if ( $wp_query->current_post === 0 || ( $prev_event_month != $event_month || ( $prev_event_month == $event_month && $prev_event_year != $event_year ) ) ) {
       				$html .= sprintf( "<span class='tribe-events-list-separator-month accordion_toggle'>%s</span>", tribe_get_start_date( $post, false, 'F Y' ) );
       			}
   
       			/*
       			 * If this event year is different to the year of the previous event in the loop,
       			 * and it's not it's not the first event in the loop (we don't want to start the loop with a year separator)
       			 */
       			if ( $wp_query->current_post > 0 && $prev_event_year != $event_year ) {
       				$html .= sprintf( "<span class='tribe-events-list-separator-year'>%s</span>", $event_year );
       			}
   
       			echo apply_filters('tribe_events_list_the_date_headers_widget', $html, $event_month, $event_year);
       		}
       	}
       ```
   
 * As you can see, the change I did is basically in the output. And I would like
   you could help to add content in footer with a similar function. I just tried
   this:
 *     ```
       function footer_widget() {
   
       		/* Month and year separators (on every month and year change) */
   
       		$show_footer = apply_filters( 'tribe_events_list_show_date_footer', true );
   
       		$html = '';
   
       		if ($show_footer) {
   
       			global $post, $wp_query;
   
       			$event_year = tribe_get_start_date( $post, false, 'Y' );
       			$event_month = tribe_get_start_date( $post, false, 'm' );
   
       			if ($wp_query->current_post > 0) {
       				$next_post = $wp_query->posts[$wp_query->current_post + 1];
       				$next_event_year = tribe_get_start_date( $next_post, false, 'Y' );
       				$next_event_month = tribe_get_start_date( $next_post, false, 'm' );
       			}
   
       			/*
       			 * If the event month changed since the last event in the loop,
       			 * or is the same month but the year changed.
       			 *
       			 */
       			if ( $wp_query->current_post === 0 || ( $next_event_month != $event_month || ( $next_event_month == $event_month && $next_event_year != $event_year ) ) ) {
       				$html .= sprintf( "<div class='footer-cont'><div></div>");
       			}
   
       			echo apply_filters('footer_widget', $html, $event_month, $event_year);
       		}
       	}
       ```
   
 * As you can see, I’m trying to add separate header and footer by month with a 
   custom div.
 * I hope you could help me with this.
    Thanks.
 * [http://wordpress.org/plugins/the-events-calendar/](http://wordpress.org/plugins/the-events-calendar/)

Viewing 1 replies (of 1 total)

 *  [Barry Hughes](https://wordpress.org/support/users/websitebakery/)
 * (@websitebakery)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/help-with-loop-function-code-and-footer-by-month/#post-4375350)
 * I’m not quite sure from your description what the actual problem is, but in any
   case I’m afraid we can’t help with custom development here on the wordpress.org
   forum as we have many support channels to cover.
 * If you think there is a functional issue or bug then of course please do let 
   us more about what you are experiencing.
 * Thanks!

Viewing 1 replies (of 1 total)

The topic ‘Help with loop function code and footer by month’ is closed to new replies.

 * ![](https://ps.w.org/the-events-calendar/assets/icon-256x256.gif?rev=2516440)
 * [The Events Calendar](https://wordpress.org/plugins/the-events-calendar/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/the-events-calendar/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/the-events-calendar/)
 * [Active Topics](https://wordpress.org/support/plugin/the-events-calendar/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/the-events-calendar/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/the-events-calendar/reviews/)

## Tags

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

 * 1 reply
 * 2 participants
 * Last reply from: [Barry Hughes](https://wordpress.org/support/users/websitebakery/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/help-with-loop-function-code-and-footer-by-month/#post-4375350)
 * Status: resolved