homepage Welcome to WebmasterWorld Guest from 54.145.209.80
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
breadcrumb nav
any quick and easy or industry standard ways?
whatson

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4504196 posted 8:19 pm on Oct 4, 2012 (gmt 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?

 

lucy24

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



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

/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

WebmasterWorld Senior Member 10+ Year Member



 
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?

coopster

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



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

mack

WebmasterWorld Administrator mack us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
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.

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

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



 
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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved