Blog Code Forum

Breadcrumb

From Wiki.cyring.fr

Jump to: navigation, search
Breadcrumb PHP function for WordPress


  1. function fBreadcrumb( $postArg , $writingDirection) {
  2.         $postScan = $postArg;
  3.         $nodeList = array();
  4.         while ($postScan) {
  5.                 $nodePage = get_page($postScan);
  6.                 $nodeList[] = sprintf( "<a href=%s>%s</a>", get_permalink($nodePage->ID), get_the_title($nodePage->ID) );
  7.                 $postScan = $nodePage->post_parent;
  8.         }
  9.         switch( $writingDirection ) {
  10.           case 'ltr':
  11.                 foreach ($nodeList as $nodeScan) $prettyStr = sprintf( " > %s %s", $nodeScan, $prettyStr );
  12.                 $prettyStr = sprintf( "<a href=%s>%s</a>%s", get_bloginfo('url'), get_bloginfo('name'), $prettyStr );
  13.                 break;
  14.           case 'rtl':
  15.                 foreach ($nodeList as $nodeScan) $prettyStr = sprintf( "%s %s < ", $prettyStr, $nodeScan );
  16.                 $prettyStr = sprintf( "%s<a href=%s>%s</a>", $prettyStr, get_bloginfo('url'), get_bloginfo('name') );
  17.                 break;
  18.         }
  19. return ($prettyStr);
  20. }

Usage in a WordPress theme, for instance home.php

  1. <div id="site-breadcrumb" ><?php print( fBreadcrumb( $post , 'ltr' ) ); ?></div>
Personal tools