sitemap.php 812 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. function generate_sitemap() {
  3. $root_url = "http" . (!empty($_SERVER['HTTPS'])?"s":"") . "://" . $_SERVER['SERVER_NAME'];
  4. $urls = [
  5. $root_url,
  6. $root_url . '/about.php',
  7. $root_url . '/subback.php'
  8. ];
  9. $json_data = file_get_contents('./data.json');
  10. $data = json_decode($json_data, false);
  11. foreach ($data as $thread) {
  12. $urls[] = $root_url . "/thread.php?id=" . $thread->id;
  13. }
  14. $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>');
  15. foreach ($urls as $url) {
  16. $url_element = $xml->addChild('url');
  17. $url_element->addChild('loc', $url);
  18. $url_element->addChild('changefreq', 'daily');
  19. }
  20. $xml->asXML('sitemap.xml');
  21. }
  22. ?>