...

Dynamic Sitemap

jbezweb
10-06-2005, 02:41 PM
Hi,

I need to make a dynamic sitemap for a CMS.

All pages are stored in a DB.

I have pulled all info out into these arrays

PageIds - all pages ids
PageNames - all page names
ParentPages - Parent page of corresponding page (id #'s, except 'root' indicating top level page).

(eg. PageIds[0] is a sub page of ParentPages[0], if ParentPages[0] = 'root' then it is the top, 1st, level)

I need it to support an infinate number of levels. My guess is that it needs to be done in a loop but can't seem to figure out how get it to work.

it should look like this:

Root Page
-Sub Page
-Sub Sub Page
-etc

Any help or direction is greatly appreciated.

jbezweb
10-06-2005, 02:43 PM
Here is what I have so far. It worked with the first 5 values but as I added more and it got more complicated it has flaws in it.

Some pointers or direction would be appreciated.

Thanks,

@ Page Language="C#" Debug="True" %>

<html>
<head>
<title>Group Test</title>
</head>

<body>
<script language="C#" runat="server">

void Page_Load()
{
string Html = "";
string [] PageIds = new string[10]{"1","2","3","4","5","6","7","8","9","10"};
string [] PageNames = new string[10]{"Homepage","About Me","Articles","Downloads","Contact Me","page6","page7","page8","page9","page10"};
string [] ParentPages = new string[10]{"root","1","4","root","2","root","root","6","7","7"};
int i;
int j;
int lvl;
int indent;
int currentJ;
string currentPage = "";
bool finished = false;

for(i=0;i<PageIds.Length;i++)
{
lvl = 1;
indent = 0;
if(ParentPages[i] == "root")
{
finished = false;
Html += "\n\t\t<div style='width:"+indent+"px;float:left'></div>" + PageNames[i] + "<br>";
currentPage = PageIds[i];

while(!finished)
{
finished = true;

for(j=0;j<PageIds.Length;j++)
{
if(currentPage == ParentPages[j])
{
lvl++;
indent += 20;
currentJ = j;
currentPage = PageIds[currentJ];
Html += "\n\t\t\t<div style='width:"+indent+"px;float:left'></div>" +
PageNames[currentJ] + "<br>";
}
}

for(j=0;j<PageIds.Length;j++)
{
if(ParentPages[j] == currentPage)
{
finished = false;
}
}
}
}
}
Output.Text = Html;
}

</script>

<form runat="server">
<asp:Label id="Output" runat="server" />
</form>

</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum