PrinceTaz Posted August 24, 2020 Share Posted August 24, 2020 Hey so I've been designing a custom forum script and I need help. I'm trying to create a breadcrumb that takes into account page title. My pages have an id, so for example: threadlist.php?id=1, viewthread.php?id=3 and so on. I used a tutorial to get started.This is what I have so far. This portion is in header.php to get session: $url =BASE_URL; $_SESSION['history'][$title] = $url; while(count($_SESSION['history']) > 4) array_shift($_SESSION['history']); breadcrumbs.php <div class="container pagination"> <nav aria-label="breadcrumb"> <ol class="breadcrumb"> <?php foreach($_SESSION['history'] as $title => $url) { echo "<li class='breadcrumb-item'><a href=". $url .">". $title ."</a></li>"; } ?> </ol> </nav> </div> It works decently well. Only problem is, when I go back to the homepage, or backwards, it doesn't remove the breadcrumb. Also, I can't click on the breadcrumb because the url isn't set up right. I know I have it set to BASE_URL buts that's only cause I can't figure out how to grab the url which would be different for every section of the site I'm on. Quote Link to comment https://forums.phpfreaks.com/topic/311379-php-breadcrumbs-for-forum/ Share on other sites More sharing options...
requinix Posted August 24, 2020 Share Posted August 24, 2020 Your breadcrumb is based on browsing history. Are you sure that's what you want? Because I really doubt it is. And if it is then you should really reconsider because that's not how they're supposed to work. Unlike the kind you hear about in stories, page breadcrumbs are not history but about location. For example, look at the breadcrumbs for this page (just above the page header): this page is located in PHP Coding Help, which is a subforum of PHP Coding, which is one of the main categories for the whole site. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311379-php-breadcrumbs-for-forum/#findComment-1580929 Share on other sites More sharing options...
PrinceTaz Posted August 25, 2020 Author Share Posted August 25, 2020 6 hours ago, requinix said: Your breadcrumb is based on browsing history. Are you sure that's what you want? Because I really doubt it is. And if it is then you should really reconsider because that's not how they're supposed to work. Unlike the kind you hear about in stories, page breadcrumbs are not history but about location. For example, look at the breadcrumbs for this page (just above the page header): this page is located in PHP Coding Help, which is a subforum of PHP Coding, which is one of the main categories for the whole site. I see, when you put it that way, I've been thinking about it all wrong the whole time. I want it to work exactly how this breadcrumbs on this forum does. So you're saying I should set up some sort of hierarchical system for the folders? Quote Link to comment https://forums.phpfreaks.com/topic/311379-php-breadcrumbs-for-forum/#findComment-1580935 Share on other sites More sharing options...
requinix Posted August 25, 2020 Share Posted August 25, 2020 I think you have your cause and effect backwards. You shouldn't be starting with "I want breadcrumbs" and then deciding "I should make folders for it". You need to consider whether you want folders in the first place. Given that you're working with some kind of forum thing, you probably do. Get those folders up and working first, add breadcrumbs to your pages second. Quote Link to comment https://forums.phpfreaks.com/topic/311379-php-breadcrumbs-for-forum/#findComment-1580936 Share on other sites More sharing options...
PrinceTaz Posted August 25, 2020 Author Share Posted August 25, 2020 7 minutes ago, requinix said: I think you have your cause and effect backwards. You shouldn't be starting with "I want breadcrumbs" and then deciding "I should make folders for it". You need to consider whether you want folders in the first place. Given that you're working with some kind of forum thing, you probably do. Get those folders up and working first, add breadcrumbs to your pages second. Okay so the forum is already pretty built and operating. If you want a link for reference, I can provide it. I do have a folder structure but very basic, admin, includes, styles. It's just I'm having a hard time understanding the logic that goes behind making breadcrumbs made for a forum. I've seen other tutorials but they use folders for the url whereas I use "id=". For example, here its "topic/311379-php-breadcrumbs-for-forum". Mine would simply be, viewtopic?id=3. Quote Link to comment https://forums.phpfreaks.com/topic/311379-php-breadcrumbs-for-forum/#findComment-1580937 Share on other sites More sharing options...
requinix Posted August 25, 2020 Share Posted August 25, 2020 Ah, okay, wrong "folders". Forget those. And don't mind what the URL looks like. But the link could be useful. You've got a topic #3. Does it belong in a forum? What is it part of? That thing is going to be part of the breadcrumb. Quote Link to comment https://forums.phpfreaks.com/topic/311379-php-breadcrumbs-for-forum/#findComment-1580938 Share on other sites More sharing options...
PrinceTaz Posted August 25, 2020 Author Share Posted August 25, 2020 (edited) So topic 3 is viewthread?id=3 which is part of the threadlist for id=1 which is part of the forum (home page). Reply would be part of viewthread which is part of threadlist which is part of the forum. Edited August 25, 2020 by PrinceTaz Quote Link to comment https://forums.phpfreaks.com/topic/311379-php-breadcrumbs-for-forum/#findComment-1580942 Share on other sites More sharing options...
PrinceTaz Posted August 25, 2020 Author Share Posted August 25, 2020 (edited) 3 hours ago, requinix said: Ah, okay, wrong "folders". Forget those. And don't mind what the URL looks like. But the link could be useful. You've got a topic #3. Does it belong in a forum? What is it part of? That thing is going to be part of the breadcrumb. Can you combine this post with the one up there? Edited August 25, 2020 by PrinceTaz Quote Link to comment https://forums.phpfreaks.com/topic/311379-php-breadcrumbs-for-forum/#findComment-1580943 Share on other sites More sharing options...
requinix Posted August 25, 2020 Share Posted August 25, 2020 It's fine, don't mind it. Sounds like the breadcrumbs for thread #3 would be: Name of your site or Forums or something > Whatever the name of the parent thread list #1 is > The title of thread #3. If thread list #1 was contained inside another list then it would go: Name of the site or whatever > Name of the grandparent thread list > Name of the parent thread list #1 > Title of the thread #3. Quote Link to comment https://forums.phpfreaks.com/topic/311379-php-breadcrumbs-for-forum/#findComment-1580944 Share on other sites More sharing options...
PrinceTaz Posted August 25, 2020 Author Share Posted August 25, 2020 24 minutes ago, requinix said: It's fine, don't mind it. Sounds like the breadcrumbs for thread #3 would be: Name of your site or Forums or something > Whatever the name of the parent thread list #1 is > The title of thread #3. If thread list #1 was contained inside another list then it would go: Name of the site or whatever > Name of the grandparent thread list > Name of the parent thread list #1 > Title of the thread #3. Would sessions be best for the job? Because also I want this to be a universal breadcrumb. So lets say I go to usercp, it would be Forum-> usercp. Would it be smart to use a conditional statement for when im browsing through threads and / or other website features i:e, memberlist or something. Quote Link to comment https://forums.phpfreaks.com/topic/311379-php-breadcrumbs-for-forum/#findComment-1580945 Share on other sites More sharing options...
requinix Posted August 25, 2020 Share Posted August 25, 2020 Sessions are for sharing data between pages. This does not involve sharing data between pages. Sessions are not appropriate. Don't get ahead of yourself. You're imagining stuff that does not need to exist. Breadcrumbs for a user CP page? You don't need anything "universal" to do that. It's Forum -> User CP. That's it. There's nothing fancy there: just a link, an arrow, and some text. You can write exactly that on your page. Breadcrumbs for things like threads and lists are potentially trickier because you don't always know the hierarchy. Threads are in subforums, but what are subforums in? Other subforums? You don't have that information ahead of time. Don't bother with anything universal. You don't need it. Just get breadcrumbs on thread pages working. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311379-php-breadcrumbs-for-forum/#findComment-1580948 Share on other sites More sharing options...
PrinceTaz Posted August 25, 2020 Author Share Posted August 25, 2020 8 hours ago, requinix said: Sessions are for sharing data between pages. This does not involve sharing data between pages. Sessions are not appropriate. Don't get ahead of yourself. You're imagining stuff that does not need to exist. Breadcrumbs for a user CP page? You don't need anything "universal" to do that. It's Forum -> User CP. That's it. There's nothing fancy there: just a link, an arrow, and some text. You can write exactly that on your page. Breadcrumbs for things like threads and lists are potentially trickier because you don't always know the hierarchy. Threads are in subforums, but what are subforums in? Other subforums? You don't have that information ahead of time. Don't bother with anything universal. You don't need it. Just get breadcrumbs on thread pages working. I'll do that, thank you! Quote Link to comment https://forums.phpfreaks.com/topic/311379-php-breadcrumbs-for-forum/#findComment-1580961 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.