Created
July 10, 2017 12:48
-
-
Save DZuz14/f9201c22eb2673ff9467f8ff1f579a91 to your computer and use it in GitHub Desktop.
XML Sitemap Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Generate the sitemap_index file | |
*/ | |
function generate_main() { | |
$main_xml = '<?xml version="1.0" encoding="UTF-8"?>'; | |
$main_xml .= "\n"; | |
$main_xml .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; | |
$main_xml .= "\n\n"; | |
// Creates two sitemap links in sitemap_index. One for posts, and one for pages. | |
$count = 0; | |
while($count < 2) { | |
$main_xml .= "<sitemap>\n"; | |
if($count == 0) | |
$main_xml .= "\t<loc>\n\t\t" . get_home_url() . "/post-sitemap.xml\n"; | |
else | |
$main_xml .= "\t<loc>\n\t\t" . get_home_url() . "/page-sitemap.xml\n"; | |
$main_xml .= "\t</loc>\n</sitemap>\n\n"; | |
$count++; | |
} | |
// Save the pages to a file | |
$file = get_home_path() . '/sitemap_index.xml'; | |
$open = fopen($file, "a"); | |
ftruncate($open, 0); | |
$main_xml .= "</sitemapindex>"; | |
fputs($open, $main_xml); | |
fclose($open); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment