I have a loop on my archive-tour page in which I output dates of on week after then the selected date.
<ul class="uol">
<?php
$start = strtotime($_GET['date']);
$dates = array();
for ($i = 0; $i <= 7; $i++) {
$date = date('Y-m-d', strtotime("+$i day", $start));
$date1 = $date;
$day = date('D', strtotime($date1));
$date = explode('-', $date);
$dateinput = date('Y-m-d', strtotime("+$i day", $start));
$date = $date[2];
echo '<li class="lia"><input type="hidden" class="getdate" value="'.$dateinput.'"><a href="#tabs-0" class="date">' . $date . ' ' . $day . '</a></li>';
}
?>
<li class="lia" style="background-color:blue"><a style="background- color:blue" href="#tabs-0" class="date tdate"></a></li>
</ul>
Here i have another loop on buttons as seen below. 1:00 am - 2:00 am......
<button type="button" style="background-color:blue" id="ttime<?php echo $post->ID?>" class="btn btn-default time-pick tt_time" value=""></button>
for ($i = 0; $i <= 23; $i++) {
am = "";
if ($i <= 12) {
$am = "am";
} else {
$am = "pm";
}
echo '<button type="button" class="btn btn-default">' . $i.':00 ' . $am . ' - ' . ++$i .':00 '. $am . '</button> ';
--$i;
}
Now user can select date and according time to book tour. i am getting the selected time and date and i want to highlight the above date and time accordingly. currently setting time and date outer then the loop. but i want to match date with selected date, if it present then highlight it and same for the time. for example in user selects 9:00 am - 10:00 am then my code add one more button with this time. i want to highlight the existing when by applying a if condition in loop that if date=selcted_date then highlight that one.
jQuery('#time<?php echo $post->ID?>').html(t_time);
$(".tdate").html(date);
how can i send the jquery variable t_time from footer page to archive page and get it on archive page in php so that i can use it in if condition. Remember its is wordpress.
In jquery you can use localStorage
.
localStorage.setItem('t_time','Your setTime' ); //set your value
And to get
localStorage.getItem('t_time'); //Get your value
Use jquery's $.post()
as follows..
var ttime = jQuery('#time<?php echo $post->ID?>').html();
$.post('php_file_name.php',{'ttime':ttime},function(data,status){
});
And in your php file..
$time = $_POST['ttime'];//get ttime send from jquery
//echo $time
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.