Test

function scrape_villages_entertainment() {
$url = ‘https://www.thevillagesentertainment.com/nightly-entertainment/’;
$response = wp_remote_get($url);
$output = ‘

Top 5 Nightly Entertainment Events

    ‘;

    if (!is_wp_error($response)) {
    $html = wp_remote_retrieve_body($response);
    libxml_use_internal_errors(true); // Ignore HTML errors
    $doc = new DOMDocument();
    $doc->loadHTML($html);
    $xpath = new DOMXPath($doc);
    // Adjust selector based on page structure (guessing common classes)
    $events = $xpath->query(‘//h2[contains(@class, “entry-title”) or contains(@class, “event-title”)]//a | //div[contains(@class, “event”) or contains(@class, “calendar-item”)]//a’);
    $count = 0;

    foreach ($events as $event) {
    if ($count >= 5) break; // Limit to 5 events
    $title = $event->textContent;
    $link = $event->getAttribute(‘href’);
    // Ensure link is absolute
    if (strpos($link, ‘http’) !== 0) {
    $link = ‘https://www.thevillagesentertainment.com’ . $link;
    }
    $output .= ‘

  • ‘ . esc_html(trim($title)) . ‘
  • ‘;
    $count++;
    }
    } else {
    $output .= ‘

  • Could not load events. Try again later!
  • ‘;
    }

    $output .= ‘

‘;
return $output;
}
add_shortcode(‘villages_events’, ‘scrape_villages_entertainment’);

Content retrieved from: https://www.thevillagesentertainment.com/nightly-entertainment/.

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar