?
Solved

Still sitemap issues

Posted on 2009-05-06
5
Medium Priority
?
217 Views
Last Modified: 2012-05-06
Hi, I recently posted a question and is just has not worked for me in the end.

I need a sitemap generator script that will generate an xml sitemap and a html sitemap too and save it to the root.

I also need to be able to set folders and files which I don't want to appear in the list.

I bought a generator from http://www.xml-sitemaps.com/ but it's not working properly and support there is really poor so I'm looking for another script that will do the job.

Can anyone help please?

thanks

st3vo
0
Comment
Question by:ST3VO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
thehagman earned 2000 total points
ID: 24312929
The attached code is a slight modification of what generates my sitemap.
The part given here recursively looks for *.html files
For dynamic pages you'd need to know what parameters are possible.
For example, you may have to make a mysql_query "SELECT id from ArticleTable", and for each entry $id call
SitemapUrl("/showarticle.php?id=$id", date("Y-m-d"), 1.0, 'weekly');
<?
$basedir = $_SERVER['DOCUMENT_ROOT'];
$indextime = date("Y-m-d",filemtime("$basedir/index.html"));
 
function SitemapUrl($U,$T,$P,$F) {
?>
 <url>
  <loc>http://www.mydomain.com<?=$U?></loc>
  <lastmod><?=$T?></lastmod>
  <changefreq><?=$F?></changefreq>
  <priority><?=$P?></priority>
 </url>
<?}
 
?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
<?
SitemapUrl('/', $indextime, 0.4, 'monthly');
 
function ListHtml($Dir,$Url) {
        $handle = @opendir($Dir);
        if ($handle !== false) {
                while (($file = readdir($handle)) !== false) {
                        $t = filetype($Dir.$file);
                        if ($file == '.' || $file == '..') {
                                // self or parent -- ignore
                        } else if ($t == 'dir') {
                                $file .= '/';
                                ListHtml($Dir.$file, $Url.$file);
                        } else if ($t == 'file' && pathinfo($file,PATHINFO_EXTENSION) == 'html') {
                                $T = date('Y-m-d',filemtime($Dir.$file));
                                $pr = 0.6; $fr = 'monthly';
                                // e.g. make "news" more important
                                if (strstr($Url,'/news/')) { $pr = 1.0; $fr = 'weekly'; }
                                SitemapUrl($Url.$file,$T,$pr,$fr);
                        }
                }
                closedir($handle);
        } else {
                echo "<!-- failed to open $Dir -->\n";
        }
}
 
ListHtml($basedir."/", "/");
 
?>

Open in new window

0
 

Author Comment

by:ST3VO
ID: 24312981
What about searching for .php files and setting directories and files that you don't want in the sitemap?
0
 
LVL 20

Expert Comment

by:thehagman
ID: 24317748
The code I gave should be easy enough to adapt for at least some very simple scenarios.
E.g. if you have directories /A/, /B/, /C/ and don't want (C) to occur, change the line
ListHtml($basedir."/", "/");
to
ListHtml($basedir."/A/", "/A/");
ListHtml($basedir."/B/", "/B/");

I deliberately left out php files since I don't know if they require parameters.
If all your php are parameterless, you can change
} else if ($t == 'file' && pathinfo($file,PATHINFO_EXTENSION) == 'html') {
to
} else if ($t == 'file' && (pathinfo($file,PATHINFO_EXTENSION) == 'html' || pathinfo($file,PATHINFO_EXTENSION) == 'php') ) {
However, I cannot predict how dynamic your php pages are -- you may want to use the current date instead of the filetime and a different frequency setting for php files.

0
 

Author Comment

by:ST3VO
ID: 24317966
I'll give it a shot and let you know how I get on..thanks!
0
 

Author Closing Comment

by:ST3VO
ID: 31578367
Thanks a lot! :o)
0

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question