Hello Leute,
ich komme leider mit einem Problem nicht weiter: Ich will datumsabhängig Inhalte ausgeben. Ich verwende das pods-Plugin, also bitte nicht wundern wo der Code am Anfang mit der while-Schleife her kommt. Das Problem ist eigentlich nur der letzte Code-Block. Irgendwie wird mir, egal welcher Event aktiv ist, immer dasselbe, oder gar nichts ausgegeben. Ich steh auf dem Schlauch und weiß nicht einmal warum. Die Ausgabe des Datums für Testzwecke habe ich unten angeführt und die ist nämlich richtig...
Code
$Record = new Pod('messetermin');
$where = "active = true";[COLOR=Gray] // active event[/COLOR]
$Record->findRecords($orderby = 'name ASC', 1000, $where);
while ($Record->fetchRecord()) {
$name = $Record->get_field('name');
$termine = $Record->get_field('date.date');
[COLOR=YellowGreen]date_default_timezone_set('Europe/Vienna');
$today = date_i18n("d.m.Y");[/COLOR]
$i = 1; [COLOR=Gray]// no need to start with php-null[/COLOR]
foreach($termine as $val) {
$i++; [COLOR=Gray]// count[/COLOR]
// no chance to just format it as date, so we do it like this:
$val = explode(" ", $val); [COLOR=Gray]// get rid of emtpy space to [/COLOR]delete the time
$new_val = $val[0];
$new_val = preg_replace('/(\d{2})-(\d{2})-(\d{2})(.*)/', '$1.$2.$3', $new_val);[COLOR=Gray] // dots instead of "-"[/COLOR]
$new_val = explode(".", $new_val);[COLOR=Gray] // explode for re-ordering[/COLOR]
$new_val = $new_val[2] . "." . $new_val[1] . "." . $new_val[0]; [COLOR=Gray]// re-order it[/COLOR]
if($i==2) { [COLOR=Gray]// Assigning the new date to numbered vars for later usage[/COLOR]
[COLOR=Purple]$event_day_1 = $new_val;[/COLOR]
} elseif($i==3) {
$event_day_2 = $new_val;
} elseif($i==4) {
[COLOR=MediumTurquoise] $event_day_3 = $new_val;[/COLOR]
}
}
[COLOR=DarkOrange]$its_60_days_before_event = strtotime('-60 day', strtotime($event_day_1));[/COLOR]
[COLOR=Gray]/* Test the date from where we start showing or hiding content
print date('d.m.Y', $its_60_days_before_event);
print date('d.m.Y', $today);
echo $event_day_1 . " - " . $event_day_2 . " - " . $event_day_3;
*/[/COLOR]
[COLOR=Gray]// HERE WE GO WITH SHOWING AND HIDING CONTENT[/COLOR]
if([COLOR=YellowGreen]$today[/COLOR] <= [COLOR=Purple]$event_day_1[/COLOR])
[COLOR=Gray]/* Alternativ: 60 vor Event die Ausgabe starten:
[/COLOR][COLOR=DarkOrange] [COLOR=Gray]if([/COLOR]$its_60_days_before_event [COLOR=Gray]<=[/COLOR] $event_day_1[COLOR=Gray])[/COLOR][/COLOR] [COLOR=Gray]
*/[/COLOR]
{ [COLOR=Gray]// before 1st event day[/COLOR]
include_once(THEME_LIB_CONT . '/b1_willkommen_t1.php');
} elseif([COLOR=YellowGreen]$today[/COLOR] >= [COLOR=MediumTurquoise]$event_day_1[/COLOR]) {[COLOR=Gray] // after 3rd event day[/COLOR]
include_once(THEME_LIB_CONT . '/b1_danke_t1.php');
}
}
Alles anzeigen