<?php
// Génération dynamique du sitemap.xml pour WordPress
header('Content-Type: application/xml; charset=utf-8');
require_once(dirname(__FILE__).'/wp-load.php');

echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

// Pages principales
$pages = get_pages();
foreach ($pages as $page) {
    echo '<url>';
    echo '<loc>' . get_permalink($page->ID) . '</loc>';
    echo '<lastmod>' . get_the_modified_time('c', $page->ID) . '</lastmod>';
    echo '<changefreq>weekly</changefreq>';
    echo '<priority>0.8</priority>';
    echo '</url>';
}
// Annonces (posts)
$args = array('post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1);
$posts = get_posts($args);
foreach ($posts as $post) {
    echo '<url>';
    echo '<loc>' . get_permalink($post->ID) . '</loc>';
    echo '<lastmod>' . get_the_modified_time('c', $post->ID) . '</lastmod>';
    echo '<changefreq>weekly</changefreq>';
    echo '<priority>1.0</priority>';
    echo '</url>';
}
echo '</urlset>';
