Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2012
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder
    Join Date
    Oct 2010
    Posts
    127
    Thanks
    26
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New Coder
    Join Date
    Nov 2012
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    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/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #5
    New Coder
    Join Date
    Nov 2012
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •