WordPress.org

Ready to get started?Download WordPress

Forums

Breadcrumb Hack for 1.01 (24 posts)

  1. lennart
    Member
    Posted 10 years ago #

    Hi,
    I created a breadcrumb hack for the index.php. You can see it in action @ my blog. It works with WP 1.01.

    function get_breadcrumb($showRoot = true, $rootName = "Home") {
    global $p, $m, $author, $blogfilename, $s, $cat, $siteurl, $blogfilename, $tablecategories;
    echo "<div id=\"breadcrumb\">";
    if ($p || $m || $author || $s || $cat) {
    echo "$rootName > ";
    if ($p) {
    echo ""; the_title(); echo "";
    } else if ($m) {
    echo "Posts of ";
    if (strlen($m) == 6) {
    echo "" . date("F Y", strtotime($m."01")) . "";
    } else {
    echo "" . date("d.m.Y", strtotime($m)) . "";
    }
    } else if ($author) {
    $user = get_userdata($author);
    echo "Posts by $user->user_nickname";
    } else if ($s) {
    echo "Search Results for $s";
    } else if ($cat) {
    echo "Category " . get_the_category_by_ID($cat) . "";
    }
    } else if ($showRoot) {
    echo $rootName;
    }
    echo "</div>\n";
    }

    Post it here in the index.php:

    <div id="content">
    <?php get_breadcrumb(); ?>
    <?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>

    And yes, I will post it to the wiki shortly.

  2. Cena
    Member
    Posted 10 years ago #

    Ah, grasshoppah...we have trained you well.

  3. southerngal
    Member
    Posted 10 years ago #

    What's this for? I went to your blog, but unfortunately I only read English. ;)

  4. Nick Momrik
    Member
    Posted 10 years ago #

    I think it's for the portion right under the header. It reads HOME and when you click on links, it updates according to what pages/posts you are looking at.

  5. mamabean
    Member
    Posted 10 years ago #

    Very nice!!!

  6. lennart
    Member
    Posted 10 years ago #

    Yes, it's the Navigation below the header and I even left it in English (for now at least) :-)

  7. anatman
    Member
    Posted 10 years ago #

    Hey,
    Nice, thank you! How can i change the separating caracter from ">" to "::" ?
    Eduardo

  8. debwire
    Member
    Posted 10 years ago #

    Great idea. I tried to get it to work and got this error though:
    Parse error: parse error in /home/debwire/public_html/photoblog/index.php on line 216

  9. anatman
    Member
    Posted 10 years ago #

    Hy Lennart,
    I too got a parse error (on line 3 of my-hacks.php - line one is just '<?php', then your code starts - using the updated code). Any idea why?
    Thanks!

  10. davidchait
    Member
    Posted 10 years ago #

    I assume that a path breadcrumb normally stores data via a cookie, setting the 'page history' traversed or some such thing? Wouldn't think that'd be too hard to do... hmmm...
    =d

  11. Alex King
    Member
    Posted 10 years ago #

    lennart: I guess we can agree to disagree. I was reading this discussion on SimpleBits and thought this quote was pertinent:

    Breadcrumb navigation is commonly used as a method for showing the user where they are within the structure of a site — and giving them an easy way of getting back.

    It is the last part, and giving them an easy way of getting back that this hack is missing.

  12. lennart
    Member
    Posted 10 years ago #

    anatman: hmm, so I don't. If you didn't fix it yet copy your my-hacks.php to a file called my-hacks.phps and post the url. Then I can see the source.
    alexkingorg: then I aree with you (to disagree of course :) ). We both seem have a valid point. Let's carry then on to more relevant discussions...
    davidchait: no it wouldn't be too hard. I would strore the information in a session variable, preferrably in an array. Maybe someone will just throw it together for you.

  13. mr_nase
    Member
    Posted 10 years ago #

    nice, i'll use that.
    dankeschön ;)
    grüße aus dtland.

  14. TechGnome
    Moderator
    Posted 10 years ago #

    To piggyback on Alex's notion of how a breadcrumb should work is like this: If I start on the main page, click on a category, then a post, I should get this (this is my interpretation of breadcrumbs)... Home > Category > Post Name. If I then click into January, I would expect to see this: Home > Category > Post Name > January. Now, depending on how many steps I want to track (5 seems like a good number), things can start to fall off the front of the list. There's no need to track EVERYWHERE I've been, but having the last 4 or 5 places I was would be real handy.
    Home > Category > Post Name > January > Jan 20
    Category > Post Name > January > Jan 20 > Post Name
    Post Name > January > Jan 20 > Post Name > Home
    January > Jan 20 > Post Name > Home > Category
    You get the idea. To me that would be a breadcrumb to have....
    TG

  15. Chris J. Davis
    Member
    Posted 10 years ago #

    lennart: although the link you provided is interesting, a re-definition of what a breadcrumb is, is just that: a re-definition.
    Classic breadcrumb technology, which has been in effect more or less for around 8-10 years has prior art. A classic breadcrumb is just that, a trail starting with your first location and then following you wherever you go on a site, allowing you to then find your way back to where you have been.
    Fortunately we have things like prior art, which means you can't just decide one day to change what a technology or concept is at your whim.
    Just saying.
    Chris

  16. TechGnome
    Moderator
    Posted 10 years ago #

    Jesuit. I agree with your definition of a breadcrumb. In fact, the best place I've seen it implemented in the manner we discussed can be found here: http://www.qwikiwiki.com ... far right, the Recently Visited list.
    lennart: I tried to ready every post in that thread, but got bored. The problem is that I don't think most of the posters truely understood the intent behind breadcrumbs. Everyone wanted to treat it as a You Are Here (YAH) indicator. Which it isn't. It's a "How in the @#$% did I get HERE?"
    TG

  17. chuckg
    Member
    Posted 10 years ago #

    I was curious if what I have on my site is an example of breadcrumb ...
    http://www.blindmuse.com
    If you click into archives it shows you where you've gone, if you click into a post specifically it shows you where you are in concerns to topics, months, etc. Granted, I don't include links for the user to back out again, but that is a simple addition. If what I've done is correct, I'll be more than happy to add it as an alternative.

  18. chuckg
    Member
    Posted 10 years ago #

    I'm working on a full breadcrumb hack now, should be done soon :)
    Example on my site listed above.

  19. Anonymous
    Unregistered
    Posted 10 years ago #

    Ah, but will it work outside the wp loop, chuckg?
    Call

  20. Anonymous
    Unregistered
    Posted 10 years ago #

    Indeed.
    I don't rely on the WP loop for breadcrumbs, I wrote my own functions which use the URL to determine what's going on. Muaha. Almost done, again.

  21. chuckg
    Member
    Posted 10 years ago #

    The above was me...I forgot to mention that what I've written is really dependent on whether or not you're using permalinks, and what kind of structure you're using as well. That's the reason it's taking me so long to package it as "generic", cause right now it's very specific to my own site and I'm hesitant to take away the functionality I enjoy. Ya know?

  22. Anonymous
    Unregistered
    Posted 10 years ago #

    A modification of the original hack:
    <?php
    function get_breadcrumb($showRoot = true, $rootName = "Home") {
    global $p, $m, $author, $blogfilename, $s, $cat, $siteurl, $blogfilename, $tablecategories;
    echo "<div id=\"breadcrumb\">";
    if ($p || $m || $author || $s || $cat) {
    echo "Blog
    ";
    if ($p) {
    echo ""; the_date('jS F Y'); echo "
    "; the_title(); echo "";
    } else if ($m) {
    echo "Posts of ";
    if (strlen($m) == 6) {
    echo "" . date("F Y", strtotime($m."01")) . "";
    } else {
    echo "" . date("d.m.Y", strtotime($m)) . "";
    }
    } else if ($author) {
    $user = get_userdata($author);
    echo "Posts by $user->user_nickname";
    } else if ($s) {
    echo "<span class=\"leveltwo\">Search: $s</span>";
    } else if ($cat) {
    echo "<span class=\"leveltwo\">Category: " . get_the_category_by_ID($cat) . "</span>";
    }
    } else if ($showRoot) {
    echo "Blog
    ";
    }
    echo "</div>\n";
    }
    ?>
    This displays:
    -
    Blog
    Date
    Post Name
    -
    when you're looking at an entry page, which I think is a bit more useful.
    --
    Call

  23. metalious
    Member
    Posted 10 years ago #

    Can some one tell me exactly where to paste the code for this last hack [Anonymous].
    Sorry to be such a newbie. But I could not make any sense of the instructions Lennart
    provided regarding where to past the code.
    Plus, is it just me or is the actual code he pasted nonexistent in the index.php?
    My index.php:
    <div id="content">
    <?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>
    <?php the_date('','<h2>','</h2>'); ?>
    <div class="storycontent">
    <?php the_content(); ?></div>
    Lennarts Example:
    <div id="content">
    <?php get_breadcrumb(); ?>
    <?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>
    This is very confusing.
    Could someone please post the exact code and where it exactly should be pasted in what file?

  24. Mark (podz)
    Support Maven
    Posted 9 years ago #

    http://technicallyincorrect.org/index.php?p=108
    charle97 left this link for you before - did it not work ?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.