Forums

Breadcrumb Trail for Pages (1 post)

  1. Getzel Rubashkin
    Member
    Posted 1 year ago #

    After a search online for quick and simple breadcrumb code that worked at more than one level depth, I put something together myself. Not having a personal platform to share it online, I am posting it here. It is basic and I'm sure the more experienced users can improve and extend it, but it was sufficient for my needs.

    Enjoy.

    The Code:

    //Check if page has ancestors - if only one parent exists, this will be an empty array
    if($post->ancestors){
    //Reverse the array so out put starts at the top of the hierarchy
    $parents = array_reverse($post->ancestors);
      foreach($parents as $parent){
         echo ' &raquo; <a href="'.get_page_link($parent).'">'.get_the_title($parent).'</a>';
      }
    }
    else if($post->parent){
    //Deal with single parent situation
    echo ' &raquo; <a href="'.get_page_link($post->parent).'">'.get_the_title($post->parent).'</a>';
    }
    //Present current title as simple text, no link
    echo ' &raquo; ';
    the_title();

    You can preface this with a link to the home page to complete the trail.

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by Getzel Rubashkin
  • This topic is not a support question
  • WordPress version: 2.9.2

Tags