. ****/ // ACTIVATION function archivesCalendar_activation($network_wide){ global $wpdb; if (isMU()){ //isMU verifyes id the site is in Multisite mode // check if it is a network activation - if so, run the activation function for each blog id if (isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) { $old_blog = $wpdb->blogid; // Get all blog ids $blogids = $wpdb->get_results("SELECT blog_id FROM $wpdb->blogs"); foreach ($blogids as $blogid) { $blog_id = $blogid->blog_id; switch_to_blog($blog_id); _archivesCalendar_activate(); } switch_to_blog($old_blog); return; } } _archivesCalendar_activate(); } function _archivesCalendar_activate(){ global $wpdb; if(!get_option( 'archivesCalendar' )) $options = array("css" => 1, "jquery" => 0, "js" => 1, "show_settings" => 1); else $options = get_option( 'archivesCalendar' ); if(isMU()) { update_blog_option($wpdb -> blogid, 'archivesCalendar', $options); add_blog_option($wpdb -> blogid, 'archivesCalendar', $options); } else { update_option('archivesCalendar', $options); add_option('archivesCalendar', $options); } } register_activation_hook(__FILE__, 'archivesCalendar_activation'); function archivesCalendar_new_blog($blog_id) { global $wpdb; if (is_plugin_active_for_network('archives-calendar/archives-calendar.php')) { $old_blog = $wpdb->blogid; switch_to_blog($blog_id); _archivesCalendar_activate(); switch_to_blog($old_blog); } } add_action( 'wpmu_new_blog', 'archivesCalendar_new_blog', 10, 6); // in case of creation of a new site in WPMU // UNINSTALL function archivesCalendar_uninstall(){ global $wpdb; if (isMU()) { $old_blog = $wpdb->blogid; $blogids = $wpdb->get_results("SELECT blog_id FROM $wpdb->blogs"); foreach ($blogids as $blogid) { $blog_id = $blogid->blog_id; switch_to_blog($blog_id); _archivesCalendar_uninstall(); } switch_to_blog($old_blog); return; } _archivesCalendar_uninstall(); } function _archivesCalendar_uninstall(){ global $wpdb; if (isMU()) delete_blog_option($wpdb->blogid, 'archivesCalendar'); else delete_option('archivesCalendar'); } register_uninstall_hook(__FILE__, 'archivesCalendar_uninstall'); // ADD Settings link in Plugins page when the plugin is activated if(!function_exists('plugin_settings_link')){ function plugin_settings_link($links) { $settings_link = 'Settings'; array_unshift($links, $settings_link); return $links; } } $acplugin = plugin_basename( __FILE__ ); add_filter( "plugin_action_links_$acplugin", 'plugin_settings_link' ); $archivesCalendar_options = get_option('archivesCalendar'); function archivesCalendar_jquery() { wp_enqueue_script('jquery'); } function calendar_archives_js() { ?> __( 'Show archives as calendar', 'archives_calendar' ), ) ); } public function widget( $args, $instance ) { extract( $args ); $title = apply_filters( 'widget_title', $instance['title'] ); echo $before_widget; if ( ! empty( $title ) ) echo $before_title . $title . $after_title; archive_calendar($instance); echo $after_widget; } public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['prev_text'] = $new_instance['prev_text']; $instance['next_text'] = $new_instance['next_text']; $instance['post_count'] = $new_instance['post_count']; return $instance; } public function form( $instance ) { $defaults = array( 'title' => __( 'Archives' ), 'next_text' => '>', 'prev_text' => '<', 'post_count' => 1, ); $instance = wp_parse_args( (array) $instance, $defaults ); $title = $instance['title']; $prev = $instance['prev_text']; $next = $instance['next_text']; $count = $instance['post_count']; ?>

'>', 'prev_text' => '<', 'post_count' => true, ); $args = wp_parse_args( (array) $args, $defaults ); extract($args); $results = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month FROM $wpdb->posts WHERE post_type='post' AND post_status='publish' AND post_password='' ORDER BY year DESC, month DESC"); $years = array(); foreach ($results as $date) { if($post_count){ $postcount = $wpdb->get_results("SELECT COUNT(ID) AS count FROM $wpdb->posts WHERE post_type='post' AND post_status='publish' AND post_password='' AND YEAR(post_date) = $date->year AND MONTH(post_date) = $date->month"); $count = $postcount[0]->count; } else $count = 0; $years[$date->year][$date->month] = $count; } $wearein = date('Y'); $nbyears = count($years); $i=$nbyears; $nextyear = ''.$next_text.''; $prevyear = ''.$prev_text.''; $cal = '
'; foreach ($years as $year => $months){ if($wearein == $year) $current = " current"; else $current = ""; $cal .= '
'; if($nbyears > 1 && $i <= $nbyears && $i > 1) $cal .= $prevyear; $cal .= ''.$year.''; if($nbyears > 1 && $year < $wearein && $i >= 1) $cal .= $nextyear; $cal .= '
'; for ( $month = 1; $month <= 12; $month++ ) { if( $month%4 == 0 ) $last = ' last'; else $last = ''; if($post_count) { if(isset($months[$month])) $count = $months[$month]; else $count = 0; $postcount = ''.$count.' '.__('Posts', 'archives_calendar').''; } else $postcount = ""; if(isset($months[$month])){ $cal .= ''; } else $cal .= '
'.strftime("%b", strtotime($month."/01/1970")).''.$postcount.'
'; } $cal .= "
\n"; $i--; } $cal .= "
"; echo "\n\n"; echo $cal; } /***** SETTINGS ******/ function archivesCalendar_admin_init(){ register_setting( 'archivesCalendar_options', 'archivesCalendar', 'archivesCalendar_options_validate' ); add_settings_section('archivesCalendar_main', '', 'archivesCalendar_options', 'archivesCalendar_plugin'); } add_action('admin_init', 'archivesCalendar_admin_init'); function ArchivesCalandarSettingsMenu() { global $archivesCalendar_options; if($archivesCalendar_options['show_settings'] == 1) $menu_name = 'Archives Calendar'; else $menu_name = ''; add_options_page('Archives Calendar Settings', $menu_name, 'manage_options', 'archives_calendar', 'archives_calendar_settings'); } function archivesCalendar_options_validate($args) { if(!isset($args['show_settings'])) $args['show_settings'] = 0; else $args['show_settings'] = 1; if(!isset($args['css'])) $args['css'] = 0; else $args['css'] = 1; if(!isset($args['jquery'])) $args['jquery'] = 0; else $args['jquery'] = 1; if(!isset($args['js'])) $args['js'] = 0; else $args['js'] = 1; return $args; } function archives_calendar_settings(){?>

/>
Include "archives-calendar.css" from the plugin. Uncheck if you copy the CSS code to your theme's style.css (recommended).
NOTE: if you have modified the default CSS file it will be restored on next plugin update.

/>
Include jQuery library into you theme. Uncheck it if you already use jQuery in your theme.
NOTE: jQuery is required to be able to change archives year, elsewhere you will only see the current year.

/>
Insert javascript code into the head. Uncheck only if you copy the code into your default js file.
NOTE:this code is required to be able to change archive year, elsewhere you will only see the current year.

Default javascript:
$(document).ready(function(e) {
	$wearein = $('.calendar-archives .current.year').attr('rel');
	$('.calendar-archives .prev-year').on('click', function(e){
		e.preventDefault();
		$('.calendar-archives .year[rel='+$wearein+']').animate({opacity: .5},300);
		$wearein -= 1;
		$('.calendar-archives .year[rel='+$wearein+']').animate({left: 0},300);
	});
	$('.calendar-archives .next-year').on('click', function(e){
		e.preventDefault();	
		$('.calendar-archives .year[rel='+$wearein+']').animate({left: '-100%'},300);
		$wearein += 1;
		$('.calendar-archives .year[rel='+$wearein+']').animate({opacity: 1},300);
	});
});


/>
Show link "Archives Calendar" in admin "Settings" menu. If unchecked you can enter settings from "Settings" link in "Plugins" page.

Donate