JezK
Edit File: index(1).php
<?php //phpinfo(); exit; require_once('../wp-load.php'); ?> <?php define('WP_USE_THEMES', false); //require('../wp-blog-header.php'); get_header(); //Include header function custom_page_title($title, $separator) { // Modify the page title here $new_title = 'New Page Title'; // Return the modified title return $new_title; } add_filter('wp_title', 'custom_page_title', 10, 2); ?> <?php include 'db_connection.php'; $totalPastEventsSql = "SELECT * FROM events WHERE event_date < CURDATE() ORDER BY event_date DESC"; $totalPastEventsCountData = $conn->query($totalPastEventsSql); $totalPastEventsCount = $totalPastEventsCountData->num_rows; ?> <!DOCTYPE html> <head> <link rel="stylesheet" href="styles.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <style> .site-content .ast-container { display: block; } a.anchor-h { color: black; } a.anchor-h:hover { color: #000000 !important; } .buttons:hover { color: #fff !important; } .buttons:focus { color: #fff !important; } .ast-builder-html-element p { padding: 0px; } .card-single img { width: 150px; height: 150px; border-radius: 10px; object-fit: contain; background-color: #e9e9e9; } .main-event { display: flex; } @media (max-width:767px) { .main-event { display: block; } } </style> </head> <body> <div> <div class="header"> <div class="container"> <h2 style="color: white" class="pt-0">Events</h2> </div> </div> <div class="container"> <h2 class="mt-4 mb-2">Our Next Event</h2> <?php $current_date = date('Y-m-d'); $today_event = ("SELECT * FROM `events` WHERE event_date >= CURDATE() AND event_date <= event_end_date ORDER BY `event_date` ASC"); $result = $conn->query($today_event); $data = $result->fetch_assoc(); if ($result->num_rows > 0) { ?> <div class="align-items-center main-event"> <div class="col-sm-12 col-lg-6 col-md-12"> <img src="../admin/assets/events/<?php echo $data['image']; ?>" class="main-image" style="width:100%; height:400px; border-radius: 15px;object-fit:contain; background-color:#e9e9e9; " /> </div> <div class="p-3"> <h5> <?php echo $data['title']; ?> </h5> <?php $fullMonth = date('F', strtotime($data['event_date'])); $fullyear = date('Y', strtotime($data['event_date'])); $start_date = date('d', strtotime($data['event_date'])); $end_date = date('d', strtotime($data['event_end_date'])); ?> <h3 class="image-text">DATE : <?php echo $fullMonth . " " . $start_date; ?> <?php if (!empty($data['event_end_date'])) { // Check if start and end date are different $end_month = date('F', strtotime($data['event_end_date'])); if ($start_date != $end_date || $fullMonth != $end_month) { // If the months are the same, just show the end date if ($fullMonth == $end_month) { echo " - " . $end_date; } else { // If different, show full end month and date echo " - " . $end_month . " " . $end_date; } } } echo ", " . $fullyear; ?> </h3> <?php if($data['event_location'] != '') { ?> <h3 class="image-text">LOCATION : <?php echo $data['event_location']; ?> </h3> <?php } ?> <div style="margin-top: 30px; margin-bottom: 10px;"> <a class="anchor-h" href="event_details.php?name=<?php echo urlencode(str_replace(' ', '_', $data['title'])) ?>&event_id=<?php echo base64_encode($data['id']) ?>"><button class="buttons px-4">View Details <i class="fa fa-arrow-right"></i></button></a> </div> </div> </div> <?php } else { ?> <center> <img src="assets/no_events.png"> </center> <?php } ?> </div> <?php $feature_events = ("SELECT * FROM `events` WHERE `event_date` <= '$current_date' AND `event_end_date` >= '$current_date' "); // echo $feature_events; $result = $conn->query($feature_events); // print_r($result); if ($result->num_rows > 0) { ?> <div class="container"> <h2 class="mt-2">Ongoing Events</h2> <div class="future_events"> <?php while ($row = $result->fetch_assoc()) { $fullMonth = date('F', strtotime($row['event_date'])); $end_fullMonth = date('F', strtotime($row['event_end_date'])); $fullyear = date('Y', strtotime($row['event_date'])); $end_fullyear = date('Y', strtotime($row['event_end_date'])); $start_date = date('d', strtotime($row['event_date'])); $end_date = date('d', strtotime($row['event_end_date'])); $event_date_same = strtotime($row['event_date']); $event_end_date_same = strtotime($row['event_end_date']); $currentMonth = date("F"); ?> <a class="anchor-h" href="event_details.php?name=<?php echo str_replace(' ', '_', $row['title']); ?>&event_id=<?php echo base64_encode($row['id']); ?>"> <div class="cards"> <div class="card-single"> <img src="../admin/assets/events/<?php echo $row['image']; ?>" class="card-image" /> <div class="card-text"> <h6> <?php echo $row['title']; ?> </h6> <p><span>Date:</span> <?php if ($row['event_end_date'] != '') { ?> <?php if ($start_date == $end_date) { echo $fullMonth . ' ' . $start_date . ', ' . $fullyear; } else if ($fullMonth != $end_fullMonth) { echo $fullMonth . ' ' . $start_date . ' - ' . $end_fullMonth . ' ' . $end_date . ', ' . $end_fullyear; } else { echo $fullMonth . ' ' . $start_date . ' - ' . $end_date . ', ' . $end_fullyear; } ?> <?php } else { ?> <?php echo $fullMonth . ' ' . $start_date . ', ' . $fullyear; ?> <?php } ?> </p> <p><span>Location:</span> <?php echo $row['event_location']; ?> </p> </div> </div> </div> </a> <?php } ?> </div> </div> <?php } ?> <div class="container"> <h2 class="mt-2">Future Events</h2> <div class="future_events"> <?php //$feature_events = ("SELECT * FROM `events` WHERE event_date BETWEEN CURDATE()+1 AND DATE_ADD(CURDATE(), INTERVAL 300 DAY) ORDER BY `event_date` ASC"); $feature_events = "SELECT * FROM `events` WHERE event_date >= DATE_ADD(CURDATE(), INTERVAL 1 DAY) AND event_date <= DATE_ADD(CURDATE(), INTERVAL 300 DAY) ORDER BY `event_date` ASC"; $result = $conn->query($feature_events); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $fullMonth = date('F', strtotime($row['event_date'])); $end_fullMonth = date('F', strtotime($row['event_end_date'])); $fullyear = date('Y', strtotime($row['event_date'])); $end_fullyear = date('Y', strtotime($row['event_end_date'])); $start_date = date('d', strtotime($row['event_date'])); $end_date = date('d', strtotime($row['event_end_date'])); $event_date_same = strtotime($row['event_date']); $event_end_date_same = strtotime($row['event_end_date']); $currentMonth = date("F"); //echo $currentMonth; ?> <a class="anchor-h" href="event_details.php?name=<?php echo str_replace(' ', '_', $row['title']); ?>&event_id=<?php echo base64_encode($row['id']); ?>"> <div class="cards"> <div class="card-single"> <img src="../admin/assets/events/<?php echo $row['image']; ?>" class="card-image" /> <div class="card-text"> <h6> <?php echo $row['title']; ?> </h6> <p><span>Date:</span> <?php if ($row['event_end_date'] != '') { ?> <?php if ($start_date == $end_date) { echo $fullMonth . ' ' . $start_date . ', ' . $fullyear; } else if ($fullMonth != $end_fullMonth) { echo $fullMonth . ' ' . $start_date . ' - ' . $end_fullMonth . ' ' . $end_date . ', ' . $end_fullyear; } else { echo $fullMonth . ' ' . $start_date . ' - ' . $end_date . ', ' . $end_fullyear; } ?> <?php } else { ?> <?php echo $fullMonth . ' ' . $start_date . ', ' . $fullyear; ?> <?php } ?> </p> <?php if($row['event_location'] != null) { ?> <p><span>Location:</span> <?php echo $row['event_location']; ?> <?php } ?> </p> </div> </div> </div> </a> <?php } } else { ?> <p> No events found </p> <?php } ?> </div> </div> <div class="container"> <h2 class="mt-2">Past Events</h2> <div class="future_events past_event"> <?php $limit = 6; $increment = 0; $past_events = "SELECT * FROM events WHERE event_date < CURDATE() ORDER BY event_date DESC LIMIT $limit"; $result = $conn->query($past_events); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $fullMonth = date('F', strtotime($row['event_date'])); $end_fullMonth = date('F', strtotime($row['event_end_date'])); $fullyear = date('Y', strtotime($row['event_date'])); $end_fullyear = date('Y', strtotime($row['event_end_date'])); $start_date = date('d', strtotime($row['event_date'])); $end_date = date('d', strtotime($row['event_end_date'])); $event_date_same = strtotime($row['event_date']); $event_end_date_same = strtotime($row['event_end_date']); ?> <div id="<?php echo $row['id']; ?>"> <a class="anchor-h" href="event_details.php?name=<?php echo urlencode(str_replace(' ', '_', $row['title'])) ?>&event_id=<?php echo base64_encode($row['id']) ?>"> <div class="cards"> <div class="card-single"> <img src="../admin/assets/events/<?php echo $row['image']; ?>" class="card-image" /> <div class="card-text"> <h6><span></span> <?php echo $row['title']; ?> </h6> <?php if ($event_date_same !== $event_end_date_same) { ?> <p><span>Date:</span> <?php if ($row['event_end_date'] != '') { ?> <?php if ($start_date == $end_date) { echo $fullMonth . ' ' . $start_date . ', ' . $fullyear; } else if ($fullMonth != $end_fullMonth) { echo $fullMonth . ' ' . $start_date . ' - ' . $end_fullMonth . ' ' . $end_date . ', ' . $end_fullyear; } else { echo $fullMonth . ' ' . $start_date . ' - ' . $end_date . ', ' . $end_fullyear; } ?> <?php } else { ?> <?php echo $fullMonth . ' ' . $start_date . ', ' . $fullyear; ?> <?php } ?> </p> <?php } ?> <?php if($row['event_location'] != null) { ?> <p><span>Location:</span> <?php echo $row['event_location']; ?> <?php } ?> </div> </div> </div> </a> </div> <?php } } else { ?> <p> No events found </p> <?php } ?> <div id="load_more_events" style="display: none;" data-limit="<?php echo $limit + $increment; ?>"></div> </div> <div class="view-button" style="margin-top: 30px; margin-bottom: 50px;"> <button class="buttons" id="view_more_button" onclick="event_view_more()">View more <i class="fa fa-arrow-right"></i></button> </div> </div> </div> </body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> let totalPastEventsCount = <?php echo $totalPastEventsCount ?> function event_view_more() { var limit = $('#load_more_events').data('limit'); $.ajax({ url: 'fetch_more_events.php', method: 'POST', data: { limit: limit }, success: function(response) { past_html = $('.past_event').html() past_html += response $('.past_event').html(''); $('.past_event').append(past_html); let increment = 4; $('#load_more_events').data('limit', limit + increment); // $('#load_more_events').data('limit', limit + <?php //echo $increment; ?>); // console.log(limit,'limit') // console.log(totalPastEventsCount,'totalPastEventsCount') if ((limit+increment) >= totalPastEventsCount) { $('#view_more_button').hide(); } // if (response.trim() == '') { // $('#view_more_button').hide(); // } } }); } </script> </html> <?php get_footer(); //Include header ?>