Msg#: 4504196 posted 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?
Msg#: 4504196 posted 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).
Msg#: 4504196 posted 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.
Msg#: 4504196 posted 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:
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.