add correct meta calendar
This commit is contained in:
@@ -1,43 +1,65 @@
|
||||
<?php
|
||||
|
||||
setlocale(LC_ALL, 'ru_RU');
|
||||
date_default_timezone_set('Europe/Moscow');
|
||||
|
||||
function calend_block($month, $year, $script=false){
|
||||
|
||||
$args = array(
|
||||
$find_sql = "
|
||||
SELECT `post_id`
|
||||
FROM `wp_postmeta`
|
||||
WHERE `meta_key` = 'startevent' AND `meta_value` BETWEEN '$year-$month-01T00:00:00' AND '$year-$month-31T23:59:59'
|
||||
";
|
||||
|
||||
|
||||
$items = db_get($find_sql);
|
||||
|
||||
$ins = str_to_in($items);
|
||||
|
||||
if ($ins !== '') {
|
||||
|
||||
$posts = db_get("
|
||||
SELECT ID, post_date, post_title FROM `wp_posts` WHERE ID IN ($ins)
|
||||
");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/** $args = array(
|
||||
'numberposts' => -1,
|
||||
'category' => 61, // 61 - мероприятия
|
||||
'orderby' => 'date',
|
||||
'order' => 'ASC',
|
||||
|
||||
'date_query' => array(
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'after' => array( // после этой даты
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
'day' => 1,
|
||||
),
|
||||
'before' => array( // до этой даты
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
'day' => 31,
|
||||
),
|
||||
// 'inclusive'=> true
|
||||
)
|
||||
),
|
||||
|
||||
'key' => 'startevent',
|
||||
'value' => array( "$year-$month-01T00:00:00", "$year-$month-31T23:59:59" ),
|
||||
'compare' => 'BETWEEN',
|
||||
'type' => 'DATE'
|
||||
),
|
||||
),
|
||||
'post_type' => 'post',
|
||||
'post_status' => 'publish, future',
|
||||
'suppress_filters' => true, // подавление работы фильтров изменения SQL запроса
|
||||
);*/
|
||||
|
||||
$args = array(
|
||||
'numberposts' => -1,
|
||||
'post__in' => $ins
|
||||
);
|
||||
|
||||
$posts = get_posts($args);
|
||||
//$posts = get_posts($args);
|
||||
|
||||
$events = [];
|
||||
|
||||
foreach ($posts as $post){
|
||||
$key = date('d.m.Y', strtotime($post->post_date));
|
||||
$events[$key]['text'] = $post->post_title;
|
||||
$events[$key]['link'] = get_permalink($post->ID);
|
||||
if (is_array($posts)){
|
||||
|
||||
foreach ($posts as $post){
|
||||
$eventdate = get_post_meta($post['ID'], 'startevent', true);
|
||||
$key = date('d.m.Y', strtotime($eventdate));
|
||||
$events[$key]['text'] = $post['post_title'];
|
||||
$events[$key]['link'] = get_permalink($post['ID']);
|
||||
|
||||
}
|
||||
|
||||
}?>
|
||||
|
||||
<div id="event-calendar">
|
||||
|
||||
@@ -9,7 +9,9 @@ class Calendar
|
||||
*/
|
||||
public static function getMonth($month, $year, $events = array())
|
||||
{
|
||||
$months = array(
|
||||
|
||||
|
||||
$months = array(
|
||||
1 => 'Январь',
|
||||
2 => 'Февраль',
|
||||
3 => 'Март',
|
||||
@@ -67,7 +69,7 @@ class Calendar
|
||||
$class = '';
|
||||
}
|
||||
|
||||
$event_show = false;
|
||||
/** $event_show = false;
|
||||
$event_text = '';
|
||||
$event_link = '';
|
||||
if (!empty($events)) {
|
||||
@@ -96,14 +98,24 @@ class Calendar
|
||||
$event_link = $text['link'];
|
||||
}
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
if ($day < 10)
|
||||
$day_str = "0$day";
|
||||
else
|
||||
$day_str = $day;
|
||||
|
||||
$arr_key = "$day_str.$month.$year";
|
||||
|
||||
|
||||
|
||||
if ($event_show) {
|
||||
//if ($event_show) {
|
||||
if (isset($events[$arr_key])) {
|
||||
|
||||
|
||||
$out.= '<td class="calendar-day ' . $class . ' calendar-event">';
|
||||
if (!empty($event_text)) {
|
||||
$out.= '<div class="calendar-popup" ><a href="'.$event_link.'" title="'.$event_text.'">'.$day.'</a></div>';
|
||||
}
|
||||
$out.= '<div class="calendar-popup" ><a href="'.$events[$arr_key]['link'].'" title="'.$events[$arr_key]['text'].'">'.$day.'</a></div>';
|
||||
|
||||
$out.= '</td>';
|
||||
} else {
|
||||
$out.= '<td class="calendar-day ' . $class . '">' . $day . '</td>';
|
||||
|
||||
Reference in New Issue
Block a user