Skip to content

Instantly share code, notes, and snippets.

@ivankravchenko
Last active December 11, 2015 20:38
Show Gist options
  • Save ivankravchenko/4656365 to your computer and use it in GitHub Desktop.
Save ivankravchenko/4656365 to your computer and use it in GitHub Desktop.
Simple breadcrumbs plugin, which is based on current URI location
<?php
function the_breadcrumbs($uri = null) {
$displayHome = false;
$displayThis = false;
$homepageId = 105;
if ($uri == null) {
$uri = $_SERVER['REQUEST_URI'];
$displayHome = true;
$displayThis = true;
}
$uri = preg_replace('/^http:\/\/[^\/]+/', '', $uri);
$uriParts = explode('/', $uri);
if ($displayHome)
the_shortinsert($homepageId, 'link');
if (count($uriParts > 2)) {
$uriParts = array_slice($uriParts, 1, count($uriParts) - 3);
$menu = wp_get_nav_menu_items('main-menu-' . ICL_LANGUAGE_CODE);
$url2title = array();
foreach ($menu as $menuItem) {
$key = $menuItem->url;
$key = preg_replace('/^http:\/\/[^\/]+/', '', $key);
$url2title[$key] = $menuItem->title;
}
unset($menu);
$uri = '/';
$firstPart = true;
foreach ($uriParts as $uriPart) {
$uri .= $uriPart . '/';
if (preg_match('/publications\/topics/', $uri)) continue;
if (preg_match('/publications\/tags/', $uri)) continue;
if (! ($firstPart && in_array($uriPart, array('ru', 'en', 'uk', 'de'))))
echo '<a href="' . $uri . '" title="' . esc_attr($url2title[$uri]) . '">'
. $url2title[$uri] . '</a> ';
$firstPart = false;
}
}
if ($displayThis) {
if (is_archive()) {
echo '<span>' . single_cat_title( '', false ) . '</span>';
} else {
echo '<span>' . get_the_title() . '</span>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment