I was wondering how can I create a sitemap using PHP & MySQL and is there any sitemap design examples you know of?
I use this on my site, it works well and you can point Google's webmaster tools to "this_file.php" and it works wonders!
<?php header("Content-type: text/xml"); echo'<?xml version=\'1.0\' encoding=\'UTF-8\'?>'; 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">'; include '../include.php'; $sql = mysql_query("select blah from bleh"); while ($string = mysql_fetch_array($sql)){?> <url> <loc>http://www.domain.com/dir/<?echo $string['value'];?>/index.php</loc> <changefreq>weekly</changefreq> </url> <?php } ?> </urlset>
The question is very vague -- we would need to know a lot more about the rest of your site before you'll get a good answer.
It depends on the structure of your page and what you want included in the map.
If your site is relatively static, then you should save your sitemap as a static page, so it doesn't cause extra processing every time its loaded. But if your site gets updated frequently, then you may need to refresh the map often, so a dynamic one that refreshes every time it is loaded may be better.
If your PHP site has a CMS structure and all your pages are included in the CMS, then it should be relatively simple to run through the database and pull out links to all your pages (depending, of course, on the structure of your CMS).
On the other hand, if your site is not structured in a way that lets you do this, or you want to limit the pages that are shown on the map, then you may find it easier to run a spider across the site and store the results.
There are plenty of existing site map programs already written. I googled php sitemap generator, and got a whole stack of results, of which quite a few look like they could be useful to you, even if only so you can download them to study their source code.
© 2022 - 2024 — McMap. All rights reserved.
sitemap.xml
for search engines? Or one for the user to view? If the latter, these things (mostly) went out of style in the last millennium. – Ashurbanipal