
if (!function_exists('get_img_url')) {
    function get_img_url($thumb_path, $site_url) {
        $ph = 'https://images.unsplash.com/photo-1585829365295-ab7cd400c167?q=80&w=800';
        if (empty($thumb_path)) return $ph;
        
        $doc_root = isset($_SERVER['DOCUMENT_ROOT']) && $_SERVER['DOCUMENT_ROOT'] ? $_SERVER['DOCUMENT_ROOT'] : dirname(__DIR__);
        $path = rtrim($doc_root, '/') . '/wp-content/uploads/' . ltrim($thumb_path, '/');
        
        if (file_exists($path)) {
            return rtrim($site_url, '/') . '/wp-content/uploads/' . ltrim($thumb_path, '/');
        }
        
        $dir = dirname($path);
        $base = basename($thumb_path);
        
        // Remove trailing numbers like -215 or -150x150
        $search_base = preg_replace('/-\d+(x\d+)?(\.[a-zA-Z0-9]+)$/', '$2', $base);
        $name_only = pathinfo($search_base, PATHINFO_FILENAME);
        
        if (is_dir($dir)) {
            $files = glob($dir . '/*' . $name_only . '*.*');
            if (!empty($files)) {
                $best_match = null;
                foreach ($files as $f) {
                    if (!preg_match('/-\d+x\d+\./', basename($f))) {
                        $best_match = basename($f);
                        break;
                    }
                }
                if (!$best_match) $best_match = basename($files[0]);
                
                return rtrim($site_url, '/') . '/wp-content/uploads/' . dirname(ltrim($thumb_path, '/')) . '/' . $best_match;
            }
        }
        
        return $ph;
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
      <loc>https://safirhaber.com/sitemap-posts.xml</loc>
      <lastmod>2026-07-09T13:31:50+00:00</lastmod>
  </sitemap>
  <sitemap>
      <loc>https://safirhaber.com/sitemap-categories.xml</loc>
      <lastmod>2026-07-09T13:31:50+00:00</lastmod>
  </sitemap>
  <sitemap>
      <loc>https://safirhaber.com/sitemap-pages.xml</loc>
      <lastmod>2026-07-09T13:31:50+00:00</lastmod>
  </sitemap>
</sitemapindex>