<?xml version="1.0" encoding="UTF-8"?>    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
      <channel>
        <title>XML Sitemap Builder from Permalink table</title>
        <link>https://interactivetools.com/forum/forum-posts.php?XML-Sitemap-Builder-from-Permalink-table-82806</link>
        <description></description>
        <pubDate>Mon, 15 Jun 2026 01:09:18 -0700</pubDate>
        <language>en-us</language>
        <atom:link href="https://interactivetools.com/forum/forum-posts.php?rss=1&amp;XML-Sitemap-Builder-from-Permalink-table-82806" rel="self" type="application/rss+xml" />

                <item>
          <title>XML Sitemap Builder from Permalink table</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2247215#post2247215</link>
          <description><![CDATA[<p>Hi Zaba, </p>
<p>Cool, thanks for sharing this!</p>]]></description>
          <pubDate>Thu, 23 May 2024 07:32:29 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2247215#post2247215</guid>
        </item>
                <item>
          <title>XML Sitemap Builder from Permalink table</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2247209#post2247209</link>
          <description><![CDATA[<p>I have created a script called runSitemap.php which you can place on your website root directory, when you access it in the browser it will generate a sitemap.xml file and place it in your root directory. This assumes you are using the permalinks plugin, which you should!</p>
<p>Make sure your database table name is correct.</p>
<p>create a file called runSitemap.php</p>
<pre class="language-php"><code>&lt;?php
// Define your base URL
$baseUrl = '<a href="https://www.yourwebsite.com" rel="nofollow">https://www.yourwebsite.com</a>';

// Database connection (modify with your credentials)
$dsn = '<a>mysql:host=localhost;dbname=yourdatabase</a>';
$username = 'yourusername';
$password = 'yourpassword';
$options = [
    PDO::ATTR_ERRMODE =&gt; PDO::ERRMODE_EXCEPTION,
];

try {
    $pdo = new PDO($dsn, $username, $password, $options);
} catch (PDOException $e) {
    die('Database connection failed: ' . $e-&gt;getMessage());
}

// Fetch URLs from the database
$urls = [];
try {
    $query = $pdo-&gt;query('SELECT permalink FROM cmsb__permalinks WHERE old=0');
    while ($row = $query-&gt;fetch(PDO::FETCH_ASSOC)) {
        $urls[] = $row['permalink'];
    }
} catch (PDOException $e) {
    die('Query failed: ' . $e-&gt;getMessage());
}

// Debugging: output the URLs to ensure they are fetched correctly
if (empty($urls)) {
    die('No URLs found or there was an error fetching them.');
}

// Function to generate the sitemap XML
function generateSitemap($baseUrl, $urls) {
    $sitemap = '&lt;?xml version="1.0" encoding="UTF-8"?&gt;' . PHP_EOL;
    $sitemap .= '&lt;urlset xmlns="<a href="http://www.sitemaps.org/schemas/sitemap/0.9" rel="nofollow">http://www.sitemaps.org/schemas/sitemap/0.9</a>"&gt;' . PHP_EOL;
    
    foreach ($urls as $url) {
        // Ensure there are no leading/trailing slashes in the URL
        $trimmedUrl = trim($url, '/');
        $fullUrl = $baseUrl . '/' . $trimmedUrl . '/';
        $sitemap .= '  &lt;url&gt;' . PHP_EOL;
        $sitemap .= '    &lt;loc&gt;' . htmlspecialchars($fullUrl) . '&lt;/loc&gt;' . PHP_EOL;
        $sitemap .= '    &lt;lastmod&gt;' . date('Y-m-d') . '&lt;/lastmod&gt;' . PHP_EOL;
        $sitemap .= '    &lt;changefreq&gt;monthly&lt;/changefreq&gt;' . PHP_EOL;
        $sitemap .= '    &lt;priority&gt;0.8&lt;/priority&gt;' . PHP_EOL;
        $sitemap .= '  &lt;/url&gt;' . PHP_EOL;
    }
    
    $sitemap .= '&lt;/urlset&gt;' . PHP_EOL;
    return $sitemap;
}

// Check if the script is accessed via a browser
if (php_sapi_name() !== 'cli' &amp;&amp; isset($_SERVER['REQUEST_METHOD'])) {
    // Generate the sitemap XML content
    $sitemapContent = generateSitemap($baseUrl, $urls);

    // Save the sitemap to the root directory
    if (file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/sitemap.xml', $sitemapContent) === false) {
        die('Failed to write sitemap.xml');
    }

    echo "Sitemap generated successfully.";
} else {
    echo "This script can only be run from a web browser.";
}
?&gt;
</code></pre>]]></description>
          <pubDate>Fri, 17 May 2024 20:04:36 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2247209#post2247209</guid>
        </item>
              </channel>
    </rss>
  