Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $_SERVER[ 'HTTP_HOST' ] = 'localhost';
- $wp_load_loc = "../../../wp-load.php";
- require_once($wp_load_loc);
- global $post;
- global $wpdb;
- function get_calendar_by_category($cat, $current_year = null, $current_month = null){
- global $post;
- global $wpdb;
- $days_in_month = cal_days_in_month(CAL_GREGORIAN, date("n"), date("Y"));
- if(!$current_year){$current_year = date("Y");}else{
- $days_in_month = cal_days_in_month(CAL_GREGORIAN, $current_month, $current_year);
- }
- if(!$current_month){$current_month = date("n");}else{
- $days_in_month = cal_days_in_month(CAL_GREGORIAN, $current_month, $current_year);
- }
- if($current_month == 1){
- $prev_month = 12;
- $prev_year = ($current_year - 1);
- }else{
- $prev_month = ($current_month - 1);
- $prev_year = $current_year;
- }
- if($current_month == 12){
- $next_month = 1;
- $next_year = ($current_year + 1);
- }else{
- $next_month = ($current_month + 1);
- $next_year = $current_year;
- }
- $args = array(
- 'cat' => $cat,
- 'posts_per_page' => -1,
- 'post_type' => 'post',
- 'post_status' => 'publish',
- 'year' => $prev_year,
- 'monthnum' => $prev_month
- );
- $check_prev_month_for_posts = query_posts( $args );
- $check_prev_month_for_posts_count = count($check_prev_month_for_posts);
- if($check_prev_month_for_posts_count){
- $prev_button = "<div id = 'calendar_toggle_prev' onclick = 'get_calendar(" . $prev_year . ", " . $prev_month . ");'><<</div>";
- }else{
- $prev_button = "";
- }
- wp_reset_query();
- $args = array(
- 'cat' => $cat,
- 'posts_per_page' => -1,
- 'post_type' => 'post',
- 'post_status' => 'publish',
- 'year' => $next_year,
- 'monthnum' => $next_month
- );
- $check_next_month_for_posts = query_posts( $args );
- $check_next_month_for_posts_count = count($check_next_month_for_posts);
- if($check_next_month_for_posts_count){
- $next_button = "<div id = 'calendar_toggle_next' onclick = 'get_calendar(" . $next_year . ", " . $next_month . ");'>>></div>";
- }else{
- $next_button = "";
- }
- wp_reset_query();
- $calendar = "";
- $calendar .= "<table class = 'category_calendar'>";
- $calendar .= "<thead><tr><td colspan = '7'><span class = 'underline_this'>" . $prev_button . $next_button . date( 'F', mktime(0, 0, 0, $current_month) ) . ' - ' . $current_year . "</span></td></tr></thead>";
- $calendar .= "<tbody><tr>";
- for($a = 0; $a <= 34; $a++){
- if($a % 7 == 0){
- $next_row = true;
- }
- if($next_row){
- $calendar .= "</tr><tr>";
- }
- $calendar .= "<td>";
- if($a != 0 && $a <= $days_in_month){
- $args = array(
- 'cat' => $cat,
- 'posts_per_page' => -1,
- 'post_type' => 'post',
- 'post_status' => 'publish',
- 'year' => $current_year,
- 'monthnum' => str_pad($current_month, 2, "0", STR_PAD_LEFT),
- 'day' => str_pad($a, 2, "0", STR_PAD_LEFT)
- );
- $check_day_for_posts = query_posts( $args );
- $title_tag = "";
- foreach( $check_day_for_posts as $post ) : setup_postdata($post);
- $title_tag .= htmlspecialchars(get_the_title(), ENT_QUOTES) . ", ";
- endforeach;
- if($title_tag){
- $styling = "class = 'active_day'";
- $link = "<a $styling title = '" . $title_tag . "' href = '" . get_bloginfo('url') . "/" . $current_year . "/" . str_pad($current_month, 2, "0", STR_PAD_LEFT) . "/" . str_pad($a, 2, "0", STR_PAD_LEFT) . "/'>";
- $end = "</a>";
- }else{
- $styling = "";
- $link = "";
- $end = "";
- }
- $calendar .= $link . "<span>" . $a . "</span>" . $end;
- wp_reset_query();
- }
- $calendar .= "</td>";
- $next_row = false;
- }
- $calendar .= "</tbody></tr></table>";
- return $calendar;
- }
- if($_GET["the_year"]){
- $the_year = $_GET["the_year"];
- }else{
- $the_year = null;
- }
- if($_GET["the_month"]){
- $the_month = $_GET["the_month"];
- }else{
- $the_month = null;
- }
- echo get_calendar_by_category(8, $the_year, $the_month);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement