Jump to content

PHP Breadcrumbs for Forum


PrinceTaz

Recommended Posts

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. 

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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 by PrinceTaz
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

  • Thanks 1
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.