Welcome to WebmasterWorld Guest from 54.196.224.166

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

breadcrumb nav

any quick and easy or industry standard ways?

     

whatson

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

WebmasterWorld Senior Member 10+ Year Member



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?

lucy24

9:55 pm on Oct 4, 2012 (gmt 0)

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



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.

whatson

8:14 pm on Oct 5, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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?

coopster

7:26 pm on Oct 14, 2012 (gmt 0)

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



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).

mack

6:44 pm on Oct 26, 2012 (gmt 0)

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



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.

vincevincevince

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

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



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.