BorysSokolov Posted May 13, 2013 Share Posted May 13, 2013 I've been trying to make a breadcrumbs navigation for a simple website which uses GET variables to determine what content to display, but it's proving a little bit more tricky than I thought. I've typed up a simple code already, but I'm looking to improve it and make it more dynamic: <?php $url_vars = array();//the correct GET variables $url_vars[0] = 'girls';//www.mywebsite.com/girls $url_vars[1] = 'boys';//www.mywebsite.com/boys $url_exp = explode('/', $_SERVER['REQUEST_URI']); $url_path = array(); foreach($url_exp as $shard){ foreach($url_vars as $var){ if($var == $shard){ $url_path[] = $shard; break; } } } require 'pre_breadcrumbs.html';//displays home crumb foreach($url_path as $crumb){ echo ' -> '; $full_crumb = ucfirst($crumb); require 'breadcrumbs.html';//creates all the crumbs } ?> Any ideas? Thanks. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 13, 2013 Share Posted May 13, 2013 Improve it how? More "dynamic" how? Quote Link to comment Share on other sites More sharing options...
BorysSokolov Posted May 13, 2013 Author Share Posted May 13, 2013 Improve it how? More "dynamic" how? I thought perhaps there was a more standard way of making breadcrumbs. Are you saying the way I did it is alright? I just want to be sure I'm not doing anything wrong. Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted May 13, 2013 Solution Share Posted May 13, 2013 It depends on how your site works. Your method for building $url_path is odd* but for all I know that's intentional. Though I will say you should have links for the crumbs if at all possible/sensible. * Normally you get breadcrumbs by looking at the structure associated with whatever page is being served. This may or may not be reflected in the URL structure: phpfreaks here only shows "topic/277963-*" in the URL but there's actually a hierarchy of Forum > PHP Coding > PHP Coding Help > This thread. Quote Link to comment Share on other sites More sharing options...
BorysSokolov Posted May 14, 2013 Author Share Posted May 14, 2013 It depends on how your site works. Your method for building $url_path is odd* but for all I know that's intentional. Though I will say you should have links for the crumbs if at all possible/sensible. * Normally you get breadcrumbs by looking at the structure associated with whatever page is being served. This may or may not be reflected in the URL structure: phpfreaks here only shows "topic/277963-*" in the URL but there's actually a hierarchy of Forum > PHP Coding > PHP Coding Help > This thread. How could I create a hierarchy like that? Quote Link to comment Share on other sites More sharing options...
requinix Posted May 14, 2013 Share Posted May 14, 2013 Depends on how your site works. Really, really depends. So how does it? Quote Link to comment Share on other sites More sharing options...
Q695 Posted May 15, 2013 Share Posted May 15, 2013 They do it on this website with something like each variable name is different, and it does urling based on what the variable name is. Quote Link to comment Share on other sites More sharing options...
BorysSokolov Posted May 15, 2013 Author Share Posted May 15, 2013 Depends on how your site works. Really, really depends. So how does it? I'm not exactly sure what to explain. Like I said, my site uses GET variables to determine what content to display. if(!empty($g)){ if($g=='boys'){ require 'men_hero.html'; }else if($g=='girls'){ require 'women_hero.html'; }else{ header('Location: http://localhost/breadcrumbs/'); } } In other files there are other variables, and all of them are reflected in the URL. I've used mod_rewrite, however, to change ~ www.mysite.com?g=girls to www.mysite.com/girls Prior to this, the breadcrumbs code runs. I don't think I understand what exactly you mean by a hierarchy? A hierarchy of variables? Quote Link to comment Share on other sites More sharing options...
Q695 Posted May 15, 2013 Share Posted May 15, 2013 History would be a simple insert of the variables based on the site you were on. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 15, 2013 Share Posted May 15, 2013 Then I think you'd be best suited by putting the breadcrumbs in those *hero.html files directly. Simple HTML. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.