Hi am new here in flarum but i manage to get a site map using database and simple php to generate sitemap for just discussion part.
Create sitemap.php on the root of your forum and paste the code below and change your db connection and your forum url in $base_url =
<?php
//sitemap.php
$connect = mysqli_connect("localhost", "username", "password here", "database name here");
$query = "SELECT id, slug FROM discussions";
$result = mysqli_query($connect, $query);
$base_url = "https://example.com/d/";
header("Content-Type: application/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . PHP_EOL;
while($row = mysqli_fetch_array($result))
{
echo '<url>' . PHP_EOL;
echo '<loc>'.$base_url. $row["id"]. "-".$row["slug"].'/</loc>' . PHP_EOL;
echo '<changefreq>daily</changefreq>' . PHP_EOL;
echo '</url>' . PHP_EOL;
}
echo '</urlset>' . PHP_EOL;
?>
Dont forget to change https://example.com with your domain, make sure the /d/ part is there.
After that add the below code to .htaccess
RewriteEngine On
RewriteRule ^sitemap\.xml/?$ sitemap.php
Now try to access example.com/sitemap.xml
I hope this help someone..