Quick and Easy Apple.com Style Breadcrumb Trail for WordPress

Almost a year ago, Janko Jovanovic posted a guide on how a little xHTML and CSS can duplicate the Apple.com store breadcrumb trail. Today, I’m going to show you how to apply Janko’s code to WordPress using Breadcrumb NavXT.

Ok, now with the requirements. You’ll need a WordPress blog (everyone should be running 2.8.1 by now), and Breadcrumb NavXT 3.2.1 (or newer).

First up, the xHTML. We are going to use the function bcn_display_list(), which was introduced in Breadcrumb NavXT 3.2.0. This will output a breadcrumb trail in list form. It is worth noting that bcn_display_list() does not output a <ul> or <ol> tag, those must be added around the calling function. We want to wrap the code with <ul> tags.

<ul class="breadcrumb_trail"> <?php if(function_exists('bcn_display_list')) { bcn_display_list(); } ?> </ul> 

Place this code where you want the breadcrumb trail to show up, I recommend placing it in your theme’s header.php file. That is all the xHTML work that we need to do. Now, on to the CSS. Open up your theme’s style.css file. We’ll start with styling the <ul>.

.breadcrumb_trail { font: 11px Arial, Helvetica, sans-serif; background: url('images/bc_bg.png') repeat-x; height:30px; line-height:30px; color:#9b9b9b; border:solid 1px #cacaca; width:100%; overflow:hidden; margin:0px; padding:0px; }

Line by line this is setting the font to the Arial/Helvetica family at the 11px size for the breadcrumb trail. Then, we set the background to an image and will repeat it horizontally across the screen. We set the height to 30 pixels for the unordered list and all text within it. This is because the background image is 30 pixels high, and the second will allow the text to be centered vertically without extra work. We set the text color to a shade of grey, this ends up being just the color of the current item breadcrumb text. We set the boarder to be 1 pixel high and a dark shade of grey in color. Next, the width of the unordered list element is set to be 100% of its containing element. We don’t want the trail to ever go outside of the preallocated area for the list, so we tell the browser to hide any overflowing content. Finally, we zero out the margin and padding.

Next we should get rid of those ugly bullet points next to each breadcrumb. Add the following code in below the code we just placed in the style.css file.

.breadcrumb_trail li { list-style:none; float:left; padding-left:10px; } 

This code will remove the bullet points next to each breadcrumb, cause the breadcrumbs to line in order from left to right and to keep 10 pixels of padding between each of them. Next, let’s style up those anchors (links).

.breadcrumb_trail a { height:30px; display:block; background:url('images/bc_separator.png') right no-repeat; padding-right: 15px; text-decoration: none; color:#454545; } 

Line by line this code will set the anchor height to 30 pixels. The anchors will be treated as block elements rather than inline elements. A background image will be used as our breadcrumb separator, we’ll set it to show up to the right of the anchor. We’ll allow 15 pixels to the right of each anchor so that the separator image displays properly. The normal anchor underline is removed, and finally we set the text color to a darkish gray.

Now we have a few, very short blocks of CSS styling for the hover condition on the anchor and the home breadcrumb icon.

.breadcrumb_trail a:hover { color:#0088ff; } 

When the anchors are hovered over this code will set the color of the anchor to a color similar to teal.

.breadcrumb_trail .home img { border: none; margin: 9px 0px; } 

This centers the home icon vertically within the home breadcrumb. Now, save your style.css file.

Time to change a few settings in the Breadcrumb NavXT page. If Breadcrumb NavXT is not already activated, activate it at this time. The next step is different depending on the version of Breadcrumb NavXT you are using.

  • For Breadcrumb NavXT versions prior to 4.0: Under the General tab in the Breadcrumb NavXT settings page, change the Home Title from “Home” to <img src="YOUR_BLOG_URL/wp-content/themes/YOUR_ACTIVE_THEME/images/home.png" alt="Home" />.
  • For Breadcrumb NavXT 4.x: Under the General tab in the Breadcrumb NavXT settings page, change the Home Template to <a class="%type%" title="Go to %title%." href="%link%"><img src="YOUR_BLOG_URL/wp-content/themes/YOUR_ACTIVE_THEME/images/home.png" alt="%title%" /></a> and the Home Template (Unlinked) to <img src="YOUR_BLOG_URL/wp-content/themes/YOUR_ACTIVE_THEME/images/home.png" alt="%title%" />.

Remember to replace YOUR_BLOG_URL with the URL for your blog, and YOUR_ACTIVE_THEME with the folder name for your currently active theme. Save the settings. Note: this will have to be changed every time you change themes. If you feel adventurous, you can directly access the bcn_breadcrumb_trail class, which will allow you to assign a dynamic Home Title.

Finally, download this archive with the three images, home.png, bc_seperator.png, and bc_bg.png (The home.png was replaced from Janko’s originals as I didn’t like it). Upload it to your current theme’s images directory. If this directory does not exist, make one and place the images in it. Now, you should have a breadcrumb trail that looks like that on Apple.com.

-John Havlik

[end of transmission, stay tuned]

Trackbacks/Pingbacks

  1. Pingback: miZine » links for 2009-08-21

  2. Pingback: How to breadcrumb navigation with Wordpress +Thesis Quickie | TroyNotes

  3. Pingback: wp-popular.com » Blog Archive » Quick and Easy Apple.com Style Breadcrumb Trail for WordPress | mtekk’s Crib

16 thoughts on “Quick and Easy Apple.com Style Breadcrumb Trail for WordPress

  1. Thanks for this tutorial. I got it working mostly and I love it, but two things that need tweaking and I am a code noob. If you go to my site, you’ll see that for some reason the home image sits a bit too low on my home page, but on other pages the home logo is centered but the 1st separator image to the right of home sits too low. Can you please help me with these tweaks? Tell me if you need more info.

    • Syd,

      Yeah it was a goof up in the guide’s code. I believe a change I made in a version of Breadcrumb NavXT released after this guide some what broke that home positioning. Anyways, I’ve updated the article to reflect the changes.

      .breadcrumb_trail .home
      {
      border: none;
      margin: 9px 0px;
      }

      Should really be:

      .breadcrumb_trail .home img
      {
      border: none;
      margin: 9px 0px;
      }

      -John Havlik

    • Yeah, you missed a very important part from the article. You must call bcn_display_list() rather than bcn_display().

      -John Havlik

  2. Where do I send all my kisses?! Thanks for this tutorial, even 2 years later. You’ve been a great help!

    • Rizwan,

      I updated the article for Breadcrumb NavXT 4.0. With the introduction of templates for each of the breadcrumb types, the Home Title option no longer accepts HTML. Instead, we play around with the Home Template and Home Template (Unlinked) options (see above).

      BTW, for HTML to show up in comments, you’ll need to use the HTML code tags. Otherwise WordPress will strip it out.

      -John Havlik

  3. This is not working for me

    <ul class="breadcrumb_trail"><?php if(function_exists('bcn_display_list')) { bcn_display_list(); } ?> </ul>

Comments are closed.