| 9:55 pm on Oct 4, 2012 (gmt 0)|
|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
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)|
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)|
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)|
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,
| 2:42 am on Nov 1, 2012 (gmt 0)|
I've found the most efficient way to do this is have MySQL store the 'acceptable' paths for each page:
id_auto-inc | true-path (text)
[place here the 'dynamic URLs', e.g. x.php?page=4&cat=8]
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.