Home

12, // total links to show ‘days’ => 3, // only show items published in last X days ‘cache’ => 20, // cache minutes ‘heading’ => ‘Latest Soccer News’, ‘show_source’ => 1, // 1 = show source name, 0 = hide ], $atts, ‘soccer_news_links’); $items_limit = max(1, (int)$atts[‘items’]); $days_limit = max(1, (int)$atts[‘days’]); $cache_min = max(5, (int)$atts[‘cache’]); $show_source = (int)$atts[‘show_source’] === 1; // Add/remove feeds as you like (must be RSS/Atom URLs). $feeds = [ ‘BBC Sport – Football’ => ‘https://feeds.bbci.co.uk/sport/football/rss.xml’, ‘Sky Sports – Football’ => ‘https://www.skysports.com/rss/12040’, ‘ESPN – Soccer’ => ‘https://www.espn.com/espn/rss/soccer/news’, ‘The Guardian – Football’=> ‘https://www.theguardian.com/football/rss’, ‘UEFA’ => ‘https://www.uefa.com/rssfeed/news/rss.xml’, ‘FIFA’ => ‘https://www.fifa.com/rss-feeds/news’, ‘Premier League’ => ‘https://www.premierleague.com/news/rss’, // may change; if it fails, remove it ]; $cache_key = ‘soccer_news_links_v1_’ . md5(json_encode([$feeds, $items_limit, $days_limit, $show_source])); $cached = get_transient($cache_key); if ($cached !== false) { return $cached; } if (!function_exists(‘fetch_feed’)) { include_once ABSPATH . WPINC . ‘/feed.php’; } $cutoff_ts = time() – ($days_limit * 86400); $all = []; foreach ($feeds as $source => $url) { $feed = fetch_feed($url); if (is_wp_error($feed)) { continue; // skip broken feeds quietly } $max = min(15, (int)$feed->get_item_quantity(15)); $items = $feed->get_items(0, $max); foreach ($items as $it) { $link = $it->get_link(); $title = $it->get_title(); $date_ts = $it->get_date(‘U’); if (!$link || !$title || !$date_ts) continue; if ($date_ts < $cutoff_ts) continue; $all[] = [ 'title' => wp_strip_all_tags($title), ‘link’ => esc_url_raw($link), ‘date’ => (int)$date_ts, ‘source’ => $source, ]; } } // Sort newest first usort($all, function ($a, $b) { return $b[‘date’] <=> $a[‘date’]; }); // Remove duplicates by link $seen = []; $unique = []; foreach ($all as $row) { if (isset($seen[$row[‘link’]])) continue; $seen[$row[‘link’]] = true; $unique[] = $row; if (count($unique) >= $items_limit) break; } if (empty($unique)) { $out = ‘‘; set_transient($cache_key, $out, $cache_min * MINUTE_IN_SECONDS); return $out; } $heading = trim($atts[‘heading’]); $out = ‘‘; // Cache output set_transient($cache_key, $out, $cache_min * MINUTE_IN_SECONDS); return $out; });