/** * Creates a formatted breadcrumb string with links to the current page's parent(s). * * - $separator string defaults to the › character but can be overridden with any string. * - current page is bolded and unlinked. * * Parameters: * $separator - the text or html character that will separate each breadcrumb (optional) * * @return Formatted <p> tag. */ function breadcrumbs($separator = ' › ') { global $_section, $_name; $bc_links = collect_breadcrumbs(get_sitemap()); $bc_array = array(); foreach ($bc_links as $name => $url) { $tag = ''; $attr = array(); # format the first item as the home link if ($name === reset(array_keys($bc_links))) { $tag = 'a'; $attr['class'] = 'home'; $attr['href'] = $url; } elseif ($name === end(array_keys($bc_links))) { $tag = 'strong'; $attr['class'] = 'active'; } else { $tag = has_index_pages() ? 'a' : 'span'; if (has_index_pages()) { $attr['href'] = $url; } $attr['class'] = 'section'; } # add the tag to the list of breadcrumbs $bc_array[] = content_tag($tag, $name, $attr); } $bc_string = format_list_with_separator($bc_array, $separator); return content_tag('p', $bc_string, array('class' => 'breadcrumbs')); }
function test_format_list_with_separator() { $list = array('one', 'two', 'three', 'four'); $this->assertEqual(format_list_with_separator($list), 'one | two | three | four'); $this->assertEqual(format_list_with_separator($list, ' * '), 'one * two * three * four'); }