0

I implemented the following script on my website. It creates automated breadcrumbs. The problem I'm having is the titles it generates. For the page you are currently on, it displays the page title which is fine. For the index files it uses the root folder names instead of the page title which is what I want it to do. For an example;

This is what it is out putting now.

Home / art / Painting

Painting I'm fine with it is the page title. Art is the folder name but I would like it to be the page title. Home I'm using a Font Awesome Icon and Im fine with that.

This is what Id like it to output

Home / Art Department / Painting

Art Department being the page title.

Here is the Javascript.

function breadcrumbs(){
  sURL = new String;
  bits = new Object;
  var x = 0;
  var stop = 0;
 var output = '<a href="http://test.ccri.edu/"><i class="fa fa-home fa-lg"></i></a> &nbsp;/&nbsp; '; 
  sURL = location.href;
  sURL = sURL.slice(8,sURL.length); 
  chunkStart = sURL.indexOf("/");
  sURL = sURL.slice(chunkStart+1,sURL.length)
  while(!stop){
    chunkStart = sURL.indexOf("/");
    if (chunkStart != -1){
      bits[x] = sURL.slice(0,chunkStart)
      sURL = sURL.slice(chunkStart+1,sURL.length);
    }else{
      stop = 1;
    }
    x++;
  }
  for(var i in bits){
    output += "<a href=\"";
    for(y=1;y<x-i;y++){
      output += "../";
    }
    output += bits[i] + "/\">" + bits[i] + "</a> &nbsp;/&nbsp; ";
  }
  document.write(output + document.title);
}
  
<!--
breadcrumbs();
 -->
</script>

Any help would be greatly appreciated! Thanks!

dbaker6
  • 39
  • 2
  • 8

0 Answers0