Jump to content

How Is It Done?


damiancds

Recommended Posts

Now, by navigation trees (don't really know what they're called) I mean what you can see right above this,the:W3Schools Forum > W3Schools > GeneralI'd like to have that working on my site but it seems rather tedious to do it by hand. Is there a way I can parse the path as a string and go from there for something like that or is there something else for it.thanks,

Link to comment
Share on other sites

There are a few ways to do this;1. Use JavaScript - Like you said, parse the string, maybe something like this:

<script type="text/javascript">var tree = location.pathname.split("/");var output = 'My Website';var path = '';for(x in tree){if(x != tree.length-1){path += '/'+tree[x];output += '<a href="/'+path+'">'+tree[x]+'</a> > ';}}document.write(output+'This Page');</script>

2. Use PHP(or another server-sided language)

<?php$tree = explode('/',$_SERVER['REQUEST_URI']);$output = 'My Website';$path = '';foreach($tree as $x => $v){if($x != count($tree)-1){$path .= '/'.$v;$output .= '<a href="/'.$path.'">'.$v.'</a> > ';}}echo $output.'This Page';?>

Link to comment
Share on other sites

Most likely each row in the forum database has a "parent" field which tells which forum is the parent. After that, what you have to do is go looping and checking the parent of each parent until you get to the point where there isn't one.A little bit like this:$forum = [forum id];$str = "[forum name]";while( [forum has parent] ) { $str = [pàrent forum name] . " > " . $str; $forum = [parent forum id];}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...