Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-08-2012, 02:43 PM   PM User | #1
tonygot
New Coder

 
Join Date: Nov 2012
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
tonygot is an unknown quantity at this point
Breadcrumbs / php?page= / javascript issue.

Hi everyone. First post here. I want first thank the search feature for getting me to this point in my website design. I have been doing this for about 3 weeks so sorry for my lack of proper terminology.

My site is setup similar to CodingForums, using (index.php?page=about) for example, so each page is always loaded in the content area of the site. I have been trying to setup a breadcrumbs feature below my navbar using JS and obviously the crumbs will only read (Home) ,(Home » index) and will not output further into the site, it just stays at home>index. I understand it is a JS scripting issue but I am not knowledgeable enough to read and change JS script without messing it up. I would like the breadcrumbs to read from the title each page using the directory structure or hierarchy I suppose instead of the history "where I have been" method.

Code:
function breadcrumbs(){
  sURL = new String;
  bits = new Object;
  var x = 0;
  var stop = 0;
 var output = "<a href=\"/\">Home</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 += bits[i] + "/\">" + bits[i] + " &nbsp;»&nbsp; ";
  }
  document.write(output + sURL.substring(0,((sURL.indexOf("."))?sURL.indexOf("."):sURL.length))
    );;
}

Thanks in advance.
tonygot is offline   Reply With Quote
Old 11-08-2012, 02:50 PM   PM User | #2
javanewbie7
Regular Coder

 
Join Date: Oct 2010
Posts: 121
Thanks: 25
Thanked 0 Times in 0 Posts
javanewbie7 is an unknown quantity at this point
I'm new too, so I'm sorry if I'm misunderstanding what you are needing. But, are you trying to set up your url to be something like www.mydomain.com/home, www.mydomain.com/page2, etc?

If so, you should be able to do that with an htaccess file, if I'm not mistaken.
javanewbie7 is offline   Reply With Quote
Old 11-08-2012, 03:00 PM   PM User | #3
tonygot
New Coder

 
Join Date: Nov 2012
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
tonygot is an unknown quantity at this point
Quote:
Originally Posted by javanewbie7 View Post
I'm new too, so I'm sorry if I'm misunderstanding what you are needing. But, are you trying to set up your url to be something like www.mydomain.com/home, www.mydomain.com/page2, etc?

If so, you should be able to do that with an htaccess file, if I'm not mistaken.
Sorry if my question is not clear. My site is already setup with php.
For example, www.mysite.com = www.mysite.com/index.php. When I click on About Us, the page is redirected to www.mysite.com/index?page=about

I have also added the breadcrumbs, but from what I understand so far is because all my content is staying in the same index page, the breadcrumbs nav will not read any further.

I am building a larger scale site with many products using MySQL and PHP and added the breadcrumbs for ease of navigation for the user. Hope this helps clarify my question.
tonygot is offline   Reply With Quote
Old 11-08-2012, 04:20 PM   PM User | #4
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,354
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
  <title></title>
<style type="text/css">
/*<![CDATA[*/
#breadcrumbs {
  position:absolute;left:100px;top:100px;width:500px;height:100px;border:solid red 1px;
}

.crumb {
  position:relative;left:0px;top:20px;width:100px;height:20px;background-Color:#FFFFCC;border:solid red 1px;margin-Left:10px;padding:5px;
}

/*]]>*/
</style>
</head>

<body>
<div id="breadcrumbs" ></div>

<script type="text/javascript">
/*<![CDATA[*/
// Simple Bread Crumbs (08-November-2012)
// by Vic Phillips - http://www.vicsjavascripts.org.uk/

function zxcBreadCrumbs(o){
 var id=o.ID,t=o.Title,obj=document.getElementById(id),days=o.Days,days=typeof(days)=='number'?days:100,re=new RegExp(id+'=[^;]+','i'),c=document.cookie.match(re)?document.cookie.match(re)[0].split("=")[1]:null,ary=[],add=true,a,z0=0,z1=0;
 if (typeof(c)=='string'){
  c=c.split(',');
  for (;z0<c.length;z0+=2){
   ary.push([c[z0],c[z0+1]]);
   if (c[z0]==t){
    add=false;
   }
  }
 }
 if (add){
  ary.push([t,window.location]);
 }
 for (;z1<ary.length;z1++){
  a=document.createElement('A');
  a.className=o.CrumbClass;
  a.href=ary[z1][1];
  a.innerHTML=ary[z1][0];
  obj.appendChild(a);
  if (ary[z1][0]==t){
   a.removeAttribute('href');
   break;
  }
 }
 document.cookie=id+'='+ary+';expires='+(new Date(new Date().getTime()+days*86400000).toGMTString())+';path=/';
}


zxcBreadCrumbs({
 ID:'breadcrumbs',   // the unique ID name of the parent node.              (string)
 CrumbClass:'crumb', // the class name of the crunb link.                   (string)
 Title:'Page 1',     // the unique page title.                              (string)
 Days:1              //(optional) the number of days to restore the crunbs. (number, default = 100)
});

/*]]>*/
</script>

</body>

</html>
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Old 11-11-2012, 10:37 AM   PM User | #5
tonygot
New Coder

 
Join Date: Nov 2012
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
tonygot is an unknown quantity at this point
Thanks Vic but that did not work for me.

I am trying to add the breadcrumbs similar to how CodingForums does. The "problem" is I am always at index.php and showing the content after the ?page=

www.mysite.com/index.php?page=about
DISPLAY= Home » index

I would like it to display, Home » About
or
Home » Category » Subcategory » Product Title

All while staying in the index.php page.

Thanks again for the replies.
tonygot is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:31 PM.


Advertisement
Log in to turn off these ads.