...

View Full Version : Breadcrumbs / php?page= / javascript issue.



tonygot
11-08-2012, 03:43 PM
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.


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.:thumbsup::thumbsup:

javanewbie7
11-08-2012, 03:50 PM
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.

tonygot
11-08-2012, 04:00 PM
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.

vwphillips
11-08-2012, 05:20 PM
<!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,r e=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>

tonygot
11-11-2012, 11:37 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum