0

Currently I am working on adding a breadcrumb without a plugin to a site. I found several possibilities on how to do that, but what I specifically want is to take one Page out of the trail.

My current trail is as follows: home - products - productgroup - productsubgroup - productname

What I want it to become is: home - productgroup - productsubgroup - productname

Does anyone have experience with this particular challenge?

I'm on the latest WP version and I am using a child theme of Twenty Ten. More info on the breadcrumb I am using: http://www.bloggingtips.com/2009/02/22/create-a-breadcrumb-trail/

1 Answer 1

0

Based on the code your used my guess is it would be as simple as adding a unset($bcarray[0]); to their code on line 15. Here is the code in it's entirety:

function write_breadcrumb() {
  $pid = $post->ID;
  $trail = "<a href='/'>Home</a>";
  if (is_front_page()) :
    // do nothing
  elseif (is_page()) :
    $bcarray = array();
    $pdata = get_post($pid);
    $bcarray[] = " &raquo; ".$pdata->post_title."\n";
    while ($pdata->post_parent) :
      $pdata = get_post($pdata->post_parent);
      $bcarray[] = " &raquo; <a href='".get_permalink($pdata->ID)."'>".$pdata->post_title."</a>\n";
    endwhile;
    $bcarray = array_reverse($bcarray);
    unset($bcarray[0]);
    foreach ($bcarray AS $listitem) :
      $trail .= $listitem;
    endforeach;
  elseif (is_single()) :
    $pdata = get_the_category($pid);
    $data = get_category_parents($pdata[0]->cat_ID, TRUE, ' &raquo; ');
    $trail .= " &raquo; ".substr($data,0,-8);
  endif;
  return $trail;
}

-Mike

4
  • Thanks Mike, for both the answer and the speed! What does the 0 mean in your additional line? update: it works brilliantly, thanks again!
    – user2015
    Commented Dec 17, 2010 at 10:25
  • @Piet: The [0] is the first element in the array named $bcarray which is also the last item added to the array which was the one you wanted removed. It's that's not clear, ask again. Thanks for the checkmark and upvote. Commented Dec 18, 2010 at 9:29
  • ah ok, so if I would have liked to remove any other parent down the line, I could change that number? Thx for the additional explanation! It's easy to copy and paste and find out it works, it's better to fully understand what's happening and why :)
    – user2015
    Commented Dec 22, 2010 at 5:53
  • @Piet - Sure. If you really want to find out what works, get a copy of PhpStorm (while it's still $49) and get the debugger set up and then you can know all, just like me. :) Commented Dec 22, 2010 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.