-
-
Save artlung/210438 to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* | |
* This is a quick way to turn a simple text file | |
* with a list of urls in a text file (sitemap-urls.txt) | |
* into a valid XML Sitemap: | |
* http://en.wikipedia.org/wiki/Sitemaps | |
* Put this file sitemap.xml.php and sitemap-urls.txt at | |
* the webroot http://example.com/sitemap.xml.php | |
* Then add the text in quotes below to your robots.txt file as a new line: | |
* "Sitemap: http://example.com/sitemap.xml.php" | |
* Questions? email [email protected] | |
*/ | |
$filename = 'sitemap-urls.txt'; | |
$urls = file($filename); | |
$filectime = filectime($filename); | |
$urls = array_map('trim',$urls); | |
$sitemap = array(); | |
foreach($urls as $url) { | |
if ($url != '') { | |
$priority = '0.5'; | |
$sitemap[] = array( | |
'loc' => $url, | |
'lastmod' => date('Y-m-d',$filectime), | |
'changefreq' => 'weekly', | |
'priority' => $priority, | |
); | |
} | |
} | |
header('Content-Type: text/xml'); | |
echo '<?xml version=\'1.0\' encoding=\'UTF-8\'?>'; | |
echo "\n"; | |
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">'; | |
echo "\n"; | |
foreach ($sitemap as $link) { | |
echo "\t<url>\n"; | |
echo "\t\t<loc>" . htmlentities($link['loc']) . "</loc>\n"; | |
echo "\t\t<lastmod>{$link['lastmod']}</lastmod>\n"; | |
echo "\t\t<changefreq>{$link['changefreq']}</changefreq>\n"; | |
echo "\t\t<priority>{$link['priority']}</priority>\n"; | |
echo "\t</url>\n"; | |
} | |
echo '</urlset>'; | |
?> |
I need your Help. how to i implement this code if any tutorial kindly share here my site is https://www.braingroom.com/
Very nice! <3
super script <3
I have a list of URLs in 10 columns of a CSV file and I need a separate sitemap for each column. Can we modify this code accordingly?
I have a list of URLs in 10 columns of a CSV file and I need a separate sitemap for each column. Can we modify this code accordingly?
Check out https://gist.github.com/artlung/311325ac4531c7a2cfa72ee4d4eb7bb5 @rk-world
Thanks very much for the script. I have created the jquery version of this on my website.
Generate sitemap from list of URLs
Thank you, exactly what I was looking for. However, it looks like the doesn't update by itself daily. In order to have it updated, I need to save the sitemap-urls.txt file. There is a way hoe I can have this done automatically everyday?
Thank you, exactly what I was looking for. However, it looks like the doesn't update by itself daily. In order to have it updated, I need to save the sitemap-urls.txt file. There is a way hoe I can have this done automatically everyday?
There are a number of different ways to automate a task, typically on a Unix based system you would use cron. But it would depend on your expectations how to use that. You’d also need to automate the URL list as well in some manner.
Thank you, exactly what I was looking for. However, it looks like the doesn't update by itself daily. In order to have it updated, I need to save the sitemap-urls.txt file. There is a way hoe I can have this done automatically everyday?
You need a cron job + the source of the URLs (database/json or whatever) and a mofified php script like this...
Thank you, exactly what I was looking for. However, it looks like the doesn't update by itself daily. In order to have it updated, I need to save the sitemap-urls.txt file. There is a way hoe I can have this done automatically everyday?
You need a cron job + the source of the URLs (database/json or whatever) and a mofified php script like this...
Hi,
Thank you for your reply.
Do you have a working solution for this?
Hello,
thank you very much for your work! Is it possible to make script for case when URLs more than 50K? It requires index sitemap file.
@Vision20202 See https://gist.github.com/artlung/613e6ac577a170bf2b4b9045486f129e for a longer list of URLs. This breaks up the longer list up into chunks according to the rules for sizing.
I tried this version but received the following error:
Undefined index: page in .../sitemap/sitemap.xml.php on line 25
line 25: $page = (int)$_GET['page'];
Please help to solve the problem.
Thank you very much!
syntax error, unexpected '?' in ..../sitemap.xml.php on line 25
Hi, I need to add the URLs manually in the sitemap eg: the University landing page (University-page.php) inside that I need to show all the Single University Pages. EG: University-page-sitemap.xml -> University/incae-sitemap.xml, University/uniandes-sitemap.xml, University/wharton-executive-education-sitemap.xml. Clicking on the University-page-sitemap.xml I need this Single University inside that in site map. can you please provide me Custom code for this.
Hi, I need to add the URLs manually in the sitemap eg: the University landing page (University-page.php) inside that I need to show all the Single University Pages. EG: University-page-sitemap.xml -> University/incae-sitemap.xml, University/uniandes-sitemap.xml, University/wharton-executive-education-sitemap.xml. Clicking on the University-page-sitemap.xml I need this Single University inside that in site map. can you please provide me Custom code for this.
Breaking up individual sitemaps into individual files should be possible. A new *.xml.php
for each, and then edit the line $filename = 'sitemap-urls.txt';
so it refers to a new txt file should be sufficient for your needs, if I'm understanding you.
thanks artlung!