deepak-rajpal
4/16/2015 - 12:58 PM

Feeds display list for files into dropdown based on year/month in file name

Feeds display list for files into dropdown based on year/month in file name

<?php
/* Get Interest Rates - Filter Dropdown - */
/* Feeds display list for files (name: 2015-04-MOR.xls). We will use array function on this to get year/months */

function get_rss_mor($feed)
{
	include_once(ABSPATH . WPINC . '/feed.php');
	$rss = fetch_feed($feed);
	// print_r ($rss);
	$count=0;
	$current_year = date("Y");
		/* Use following to check if rss error */
		/* if( is_wp_error( $rss ) ) {
			echo $rss->get_error_message();
			continue;
		} */
	$rss_items = $rss->get_items();
	/* 	Starts: Dropdown-Select Menu by extracting year from title */
		$menu_data = '<div style="text-align: right; padding-top:5px; padding-right:10px;" class=NDY>Historical: <span id="select" class="selectGrayMedium">'.$current_year.'</span><select id="moryears" class=styledGrayMedium>';
		$year_list = array();
		foreach ( $rss_items as $item ) :
			$year = strstr($item->get_title(), '-', true);
			array_push($year_list,$year);
		endforeach;
		$unique_years = array_unique ($year_list);
		rsort($unique_years,SORT_NUMERIC);
		foreach ($unique_years as $key => $value) { $menu_data .= "<option>$value</option>"; }
		$menu_data = $menu_data."</select></div>";
		print ($menu_data);
	/* 	End: Dropdown-Select Menu by extracting year from title */
	
	
	
	/* 	Starts: Mor data tables year wise */
	$mor_data = array();
	foreach ( $rss_items as $item ) :
		// Make an array of rss feed data - key as title and value as permalink
		$mor_data[$item->get_title()] = $item->get_permalink();
	endforeach;
	ksort($mor_data);	// Sort by key (actually title containing year)
	//	print_r($mor_data);
				
	$count = 0;
	foreach ( $mor_data as $title => $permalink ) :
		$year = strstr($title, '-', true);						// Get year
		$month = substr($title, 5,2);							// Get month number
		$month_name = date("F", mktime(0, 0, 0, $month, 10)); 	// Get Month name from number
		// Asign year variable for first time
		if ($count==0) { 
			$year_pointer = $year;
			// content display
		
		// check if current item year is same as last
		if ($year_pointer == $year) { $same_year_group = 1; } else { $same_year_group = 0; $year_pointer = $year; } 
		$count++;
		
		if ($same_year_group) {
			// content display
		} else {
			// content display
		}
	endforeach;
	$mor_table_data .= '</tbody></table>
			</div>';
	echo $mor_table_data;
}
?>