Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    breadcrumb ideas

    Im working on creating a breadcrumb function for my site, but I need some direction.

    The issue im having, is how to display the possibilities.

    Here are some possible results that could show up:

    Site name >> Home
    Site name >> Search
    Site name >> Forum Name
    Site name >> Forum Name >> Topic Name
    Site name >> Forum Name >> Topic Name >> Post reply
    Site name >> Users Online

    etc.

    The thing is, the things like Home, Search, and Users Online are all static, nothing needs to show up after them. But with the Forum Name stuff, it continues out. How do I pass information to a function, and get it to build the breadcrumbs?

    The way I would like to have the code created is in array format, where something like the Site name>>forum name>>topic name>> post reply would be in the format:

    PHP Code:
    $breacrumbs = array(
            
    "Site Name" => "index.php",
            
    "Forum Name" => "displayforum.php?fid=1",
            
    "Topic Name" => "displaytopic.php?tid=1",
            
    "Post Reply" => "postreply.php?tid=1",
            ); 
    But the issue, is how do I build that array? How does the information get sent to the function, and how does it change if it is a static page like Search, or Users Online?

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I guess your building a forum eh? I did that a while ago, when I build another one I will do somethings different. But things to keep in mind is if you have sub forums of main forums etc... You need a way to build out your 'parents'. So when I create a forum I have it put in the parent id's of whats above (IF anything) in order. Then it makes the bread crumb part easy. I will show you my breadcrumb function to give you some idea. I will explain things in it

    PHP Code:
        function breadcrumb($parent_list$thread_view '0'$thread ''$topic_id '')
        {
            global 
    $db;

            
    $trailArray = array();

            
    $breadcrumb "<a href=\"".session_link('index.php')."\">Home</a>";
            
    $sep "&nbsp;&nbsp;>>&nbsp;&nbsp;";
            
    $trail array_reverse(explode(','substr($parent_list0, -3)));

            if(
    $thread_view == '0') {
                
    $last_id array_pop($trail);
            }

            if(
    is_array($trail)) {
                foreach(
    $trail as $crumb) {
                    
    $forum $this->get_parent($crumb);
                    if(
    $forum['folder'] == '1') {
                        
    $breadcrumb .= $sep."<a href=\"".session_link('index.php?forumID='.$crumb)."\">".$forum['name']."</a>";
                    } else 
    $breadcrumb .= $sep."<a href=\"".session_link('forum.php?forumID='.$crumb)."\">".$forum['name']."</a>";
                }

                if(
    $thread_view == '0') {
                    
    $t_forum $this->get_parent($last_id);
                    
    $breadcrumb .= "<br /><br /><div style=\"font-size: 14px;\"><b>".$t_forum['name']."</b></div>";
                    
    $trailArray['title'] = addslashes($t_forum['name']);
                } else if(
    $thread_view == '1') {
                    
    $breadcrumb .= "<br /><br /><div style=\"font-size: 14px;\"><b>".$thread."</b></div>";
                    
    $trailArray['title'] = addslashes($thread);
                } else if(
    $thread_view == '2') {
                    
    $breadcrumb .= $sep."<a href=\"".session_link('topic.php?topicID='.$topic_id)."\">".$thread."</a>";
                    
    $breadcrumb .= "<br /><br /><div style=\"font-size: 14px;\"><b>New Post</b></div><br />";
                    
    $trailArray['title'] = "New Post";
                } else if(
    $thread_view == '3') {
                    
    $breadcrumb .= "<br /><br /><div style=\"font-size: 14px;\"><b>New Topic</b></div><br />";
                    
    $trailArray['title'] = "New Topic";
                } else if(
    $thread_view == '4') {
                    
    $breadcrumb .= $sep."<a href=\"".session_link('topic.php?topicID='.$topic_id)."\">".$thread."</a>";
                    
    $breadcrumb .= "<br /><br /><div style=\"font-size: 14px;\"><b>Edit Post</b></div><br />";
                    
    $trailArray['title'] = "Edit Post";
                }
            }

            if(
    $trailArray['title'] == ""$trailArray['title'] = "Home";
            
    $trailArray['breadcrumb'] = $breadcrumb;

            return 
    $trailArray;
        } 
    Ok in the function $parent_list; Thats basically the parent id structure. For example this is my forum;

    Code:
    ServerSide (1)
        --PHP Coding (3)
        --ASP Coding (4)
    ClientSide (2)
        --Javascript (5)
            --AJAX (6)
    Lets take that as our forum structure. The numbers in the parenthesis are the id numbers. So If I was to navigate to the PHP Coding forum, My parent list would be:

    3,1,-1 (-1 Means Absolute top no forum selected)

    Now I will reverse that order and pop off "-1". So I'm left with 1,3. Now I run a foreach on those and call the function $this->get_parent($crumb);. Which query's for the name of the forum. You ask yourself "Why query for each one, that adds all those extra queries to the page". Well I use cacheing and it just gets the name from a cache file, so no query involved .

    Ok moving on, As I run through the loop, I have a selection that says if its a "Folder" or not. Well I call this a category, so "General" would be a category and not a forum (It's just the way I did it). So it adds in the appropriate link.

    Ok now in the function you see $thread = '0'. As you can see from all my IF's and ELSE's, how I setup the LAST item on the breadcrumb trail. Allows me to setup the Edit and New post...

    And Last the $trailArray['title']; That is the meta title I use for the page for dynamic titles .

    Now all this is dependant on your parent_list structure. I noticed in the mysql forum that you are linking the post table to the thread table to the forum table. I know in my tables, the post table contains the thread_id as well as the forum id. Also in the thread table, I have last_post_id, first_post_id and forum id. So everything is there when I need it.

    Maybe this helps you, maybe not. I know it took me a while to get my breadcrumb and forum structure good. That is why I made the parent list

  • #3
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I just noticed, I have global $db in there. What for


  • #4
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    hmm, I dont think I follow your coding.

    However, my table structure is as follows if that helps explain how my things are working currently:

    Code:
    CREATE TABLE `categories` (
      `id` int(11) NOT NULL auto_increment,
      `name` varchar(50) NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
    
    CREATE TABLE `forums` (
      `id` int(11) NOT NULL auto_increment,
      `parentid` int(11) default NULL,
      `catid` int(11) default NULL,
      `name` varchar(50) NOT NULL,
      `description` longtext NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
    
    CREATE TABLE `posts` (
      `id` int(11) NOT NULL auto_increment,
      `topicid` int(11) NOT NULL,
      `posterid` int(11) NOT NULL,
      `message` longblob NOT NULL,
      `postdate` timestamp NOT NULL default CURRENT_TIMESTAMP,
      `editedon` timestamp NOT NULL default '0000-00-00 00:00:00',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
    and im actually recoding my forum system. I had one before, but i came across so many bugs that I couldnt solve, and it was old so the coding was really basic and cluttered. Im redoing everything with classes and such.

    But back to the issue at hand, with the table structure I have above, how do you see that I can do it?

  • #5
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Bottom line, you need a way to follow your forum structure. Are you using sub forums? If not it shouldn't be a problem. With the use of sub forums you have to follow the structure back to the top. You could always just query the forum your at now, get the parent forum and loop again and again... But how would you know when to stop or keep looping? I came up against that wall, thats why I build the structure when I create/edit a new forum.

  • #6
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    A forum with no parent forum has a null parentid field and a numbered catid value. So the loop sounds like a not half bad idea. May I ask for a snippit please?

    And you sound like you might be interested in working on a forum system, is that something I might be able to interest you in? I definitely could use more people on the team.

  • #7
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well I will be developing another one for my current employer here very shorty so this is something I will be tackling. Pm sent.

  • #8
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Check your PM's

  • #9
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    checked, but back to the topic at hand. With the database structure I have, how can I do this?

    Say im on page reply.php?tid=4

    That should find the name and id of the topic with id 4, then the name of the forum with the id of the topics forumid, then the forumid of its parent, rinse and repeat the last step, then the site name.

    However, the biggest issue is getting the script to know what to do differently for different pages.

  • #10
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    *bump*?

  • #11
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    *bump*

    Anyone know how I could create these breadcrumbs based on the table structure that I have?

  • #12
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Not without extra queries per breadcrumb. You can setup a recursive function for that. I suggest a structure change as stated above if you want the best performance.

  • #13
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    The best way would be to use MPTT for storage of the order of your "forums". It would allow you to get the breadcrumbs with one query and would simplify other operations.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #14
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    marek_mar, I have used MPTT before, but for this particular application I do not wish to use it.

    If I use multiple queries to run this, what would just be the code for something like that?

    @illin, I have added you on aim and msn, but I havent seen you on.

  • #15
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Basically TS just needs you to write the script for him, that's all.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •