Welcome to WebmasterWorld Guest from 54.144.44.9

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

breadcrumb nav

any quick and easy or industry standard ways?

     
8:19 pm on Oct 4, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 21, 2002
posts: 1541
votes: 0


So I am trying to code the breadcrumb nav, but there must be better easier way.

My pages are e.g. domain.com/category/sub-category/page

I want breadcrumb for Home > Category > Sub-category > Page

But of course I have pages like domain.com/category/sub-category also
Which need breadcrumb for Home > Category > Sub-category

Anyway, you get the idea. Any suggestions?
9:55 pm on Oct 4, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13210
votes: 347


But of course I have pages like domain.com/category/sub-category also
Which need breadcrumb for Home > Category > Sub-category

Maybe, maybe not. Your navigation doesn't have to correspond to your physical site structure. Minimalist form:

home > widgets > blue > bluewidgets
side by side with
home > blue stuff > widgets > bluewidgets

It doesn't matter whether that final page "really" lives at

/widgets/bluewidgets
or
/blue/bluewidgets
or
/bluewidgets
or
/products/bluewidgets

or somewhere else entirely. The more ways to get there, the better-- so long as search engines can see it's all the same page.
8:14 pm on Oct 5, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 21, 2002
posts: 1541
votes: 0


Sorry Lucy, I was not referring to the url structure, I meant how do I generate the code to create breadcrumbs. I can't work out the logic.

I was thinking something like explode the url, domain.com/category/sub-category/page.
then left with category, sub-category, and page, I then have to look up each of the rows for these pages, including their corresponding category, and find the name of the page for the link text.

Of course I also need to know how many levels of breadcrumb to go into. So I guess I count the /s and have a switch statement?
7:26 pm on Oct 14, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12541
votes: 1


Exploding the url is one way but you have already discovered the performance catch there in that you are going to have to run multiple queries against your data to discover the proper link title to go with each breadcrumb.

I prefer to build my breadcrumb nav when I retrieve the page content in a single query.

Using the former or latter will rely entirely on how your database tables are structured. (assuming you are using a database to store the content).
6:44 pm on Oct 26, 2012 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator mack is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:June 15, 2001
posts:7564
votes: 4


It really depends on how te site works. One method I have used in the past is to use content areas or categories. Every page being read from the database will then have a value assigned for its category.

Its then a case of echoing the code in html

echo"<a href+\"/\">Home</a> - <a href=\"$category\">category</a> - $page";

Its not bullet proof and there are some downsides, but for the most part it is up to the job,

Mack.
2:42 am on Nov 1, 2012 (gmt 0)

Senior Member from MY 

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 1, 2003
posts:4847
votes: 0


I've found the most efficient way to do this is have MySQL store the 'acceptable' paths for each page:

PAGES:
id_auto-inc | true-path (text)
[place here the 'dynamic URLs', e.g. x.php?page=4&cat=8]

PATHS:
id_auto-inc | page-id | path (text)
[the page-id refs the ID from 'pages', and there is an entry for each valid path that could end up at that page]

Then, your mod_rewrite (or your 404 handler) should do a lookup:
1) Check REQUEST_URI against PATHS table JOIN PAGES table
2) Internally set GET args according to true-path from PAGES table
3) include() the dynamic URL (x.php) from PAGES table
4) Add error handling for any path not found in PATHS table


A useful addition is to have support for canonical URLs - certain paths which when visited will be flagged to first redirect themselves to a 'canonical' URL with a 301 header. This avoids the possibility of duplicate content, by having only one path which is 'finally' seen for each PAGE.