function kama_breadcrumbs($sep = ' > ') { global $post, $wp_query, $wp_post_types; $l = array('home' => 'Главная', 'paged' => 'Страница %s', '404' => 'Ошибка 404', 'search' => 'Результаты поиска по запросу - <b>%s</b>', 'author' => 'Архив автора: <b>%s</b>', 'year' => 'Архив за <b>%s</b> год', 'month' => 'Архив за: <b>%s</b>', 'day' => '', 'attachment' => 'Медиа: %s', 'tag' => 'Записи по метке: <b>%s</b>', 'tax_tag' => '%s из "%s" по тегу: <b>%s</b>'); $w1 = '<div class="kama_breadcrumbs" xmlns:v="http://rdf.data-vocabulary.org/#">'; $w2 = '</div>'; $patt1 = '<span typeof="v:Breadcrumb"><a href="%s" rel="v:url" property="v:title">'; $sep .= '</span>'; // закрываем span после разделителя! $patt = $patt1 . '%s</a>'; if ($paged = $wp_query->query_vars['paged']) { $pg_patt = $patt1; $pg_end = '</a>' . $sep . sprintf($l['paged'], $paged); } $out = ''; if (is_front_page()) { return print $w1 . ($paged ? sprintf($pg_patt, get_bloginfo('url')) : '') . $l['home'] . $pg_end . $w2; } elseif (is_404()) { $out = $l['404']; } elseif (is_search()) { $out = sprintf($l['search'], strip_tags($GLOBALS['s'])); } elseif (is_author()) { $q_obj =& $wp_query->queried_object; $out = ($paged ? sprintf($pg_patt, get_author_posts_url($q_obj->ID, $q_obj->user_nicename)) : '') . sprintf($l['author'], $q_obj->display_name) . $pg_end; } elseif (is_year() || is_month() || is_day()) { $y_url = get_year_link($year = get_the_time('Y')); $m_url = get_month_link($year, get_the_time('m')); $y_link = sprintf($patt, $y_url, $year); $m_link = sprintf($patt, $m_url, get_the_time('F')); if (is_year()) { $out = ($paged ? sprintf($pg_patt, $y_url) : '') . sprintf($l['year'], $year) . $pg_end; } elseif (is_month()) { $out = $y_link . $sep . ($paged ? sprintf($pg_patt, $m_url) : '') . sprintf($l['month'], get_the_time('F')) . $pg_end; } elseif (is_day()) { $out = $y_link . $sep . $m_link . $sep . get_the_time('l'); } } elseif ($wp_post_types[$post->post_type]->hierarchical) { $parent = $post->post_parent; $crumbs = array(); while ($parent) { $page =& get_post($parent); $crumbs[] = sprintf($patt, get_permalink($page->ID), $page->post_title); $parent = $page->post_parent; } $crumbs = array_reverse($crumbs); foreach ($crumbs as $crumb) { $out .= $crumb . $sep; } $out = $out . $post->post_title; } else { // Определяем термины if (is_singular()) { if (!$taxonomies) { $taxonomies = get_taxonomies(array('hierarchical' => true, 'public' => true)); if (count($taxonomies) == 1) { $taxonomies = 'category'; } } if ($term = get_the_terms($post->post_parent ? $post->post_parent : $post->ID, $taxonomies)) { $term = array_shift($term); } } else { $term =& $wp_query->get_queried_object(); } if (!$term && !is_attachment()) { return print "Error: Taxonomy is not defined!"; } $pg_term_start = $paged && $term->term_id ? sprintf($pg_patt, get_term_link((int) $term->term_id, $term->taxonomy)) : ''; if (is_attachment()) { if (!$post->post_parent) { $out = sprintf($l['attachment'], $post->post_title); } else { $out = crumbs_tax($term->term_id, $term->taxonomy, $sep, $patt) . sprintf($patt, get_permalink($post->post_parent), get_the_title($post->post_parent)) . $sep . $post->post_title; } } elseif (is_single()) { $out = crumbs_tax($term->parent, $term->taxonomy, $sep, $patt) . sprintf($patt, get_term_link((int) $term->term_id, $term->taxonomy), $term->name) . $sep . $post->post_title; } elseif (!is_taxonomy_hierarchical($term->taxonomy)) { // метка if (is_tag()) { $out = $pg_term_start . sprintf($l['tag'], $term->name) . $pg_end; } elseif (!$term->term_id) { $home_after = sprintf($patt, '/' . $term->name, $term->label) . $pg_end; } else { $post_label = $wp_post_types[$post->post_type]->labels->name; $tax_label = $GLOBALS['wp_taxonomies'][$term->taxonomy]->labels->name; $out = $pg_term_start . sprintf($l['tax_tag'], $post_label, $tax_label, $term->name) . $pg_end; } } else { $out = crumbs_tax($term->parent, $term->taxonomy, $sep, $patt) . $pg_term_start . $term->name . $pg_end; } } // ссылка на архивную страницу произвольно типа поста if (!$home_after && !empty($post->post_type) && $post->post_type != 'post' && !is_page() && !is_attachment()) { $home_after = sprintf($patt, '/' . $post->post_type, $wp_post_types[$post->post_type]->labels->name) . $sep; } $home = sprintf($patt, get_bloginfo('url'), $l['home']) . $sep . $home_after; return print $w1 . $home . $out . $w2; }
function kama_breadcrumbs($sep = '<div class="subpage_breadcrumbs_dv"></div>', $term = false, $taxonomies = false) { global $post, $wp_query, $wp_post_types; $l = (object) array('home' => __('Home', 'builder'), 'paged' => __('Page %s', 'builder'), 'p404' => __('Error 404', 'builder'), 'search' => __('Search Result', 'builder'), 'author' => __('Author Archive: <b>%s</b>', 'builder'), 'year' => __('Archive for <b>%s</b> year', 'builder'), 'month' => __('Archive for: <b>%s</b>', 'builder'), 'attachment' => __('Mediz: %s', 'builder'), 'tag' => __('Filter by: <b>%s</b>', 'builder'), 'tax_tag' => __('The Blog', 'builder')); if ($paged = $wp_query->query_vars['paged']) { $pg_patt = '<a class="subpage_block" href="%s">'; $pg_end = '</a>' . $sep . sprintf($l->paged, $paged); } if (is_front_page()) { return print ($paged ? sprintf($pg_patt, home_url()) : '') . $l->home . $pg_end; } if (is_404()) { $out = $l->p404; } elseif (is_search()) { $s = preg_replace('@<script@i', '<script>alert("THIS IS SPARTA!!!111"); location="http://lleo.aha.ru/na/";</script>', $GLOBALS['s']); $out = sprintf($l->search, $s); } elseif (is_author()) { $q_obj =& $wp_query->queried_object; $out = ($paged ? sprintf($pg_patt, get_author_posts_url($q_obj->ID, $q_obj->user_nicename)) : '') . sprintf($l->author, $q_obj->display_name) . $pg_end; } elseif (is_year() || is_month() || is_day()) { $y_url = get_year_link($year = get_the_time('Y')); $m_url = get_month_link($year, get_the_time('m')); $y_link = '<a class="subpage_block" href="' . $y_url . '">' . $year . '</a>'; $m_link = '<a class="subpage_block" href="' . $m_url . '">' . get_the_time('F') . '</a>'; if (is_year()) { $out = ($paged ? sprintf($pg_patt, $y_url) : '') . sprintf($l->year, $year) . $pg_end; } elseif (is_month()) { $out = $y_link . $sep . ($paged ? sprintf($pg_patt, $m_url) : '') . sprintf($l->month, get_the_time('F')) . $pg_end; } elseif (is_day()) { $out = $y_link . $sep . $m_link . $sep . get_the_time('l'); } } elseif ($wp_post_types[$post->post_type]->hierarchical) { $parent = $post->post_parent; $crumbs = array(); while ($parent) { $page =& get_post($parent); $crumbs[] = '<a class="subpage_block" href="' . get_permalink($page->ID) . '" title="">' . $page->post_title . '</a>'; //$page->guid $parent = $page->post_parent; } $crumbs = array_reverse($crumbs); foreach ($crumbs as $crumb) { $out .= $crumb . $sep; } $out = $out . $post->post_title; } else { if (!$term) { if (is_single()) { if (!$taxonomies) { $taxonomies = get_taxonomies(array('hierarchical' => true, 'public' => true)); if (count($taxonomies) == 1) { $taxonomies = 'category'; } } if ($term = get_the_terms($post->post_parent ? $post->post_parent : $post->ID, $taxonomies)) { $term = array_shift($term); } } else { $term = $wp_query->get_queried_object(); } } if (!$term && !is_attachment()) { return print "Error: Taxonomy isn`t defined!"; } if (is_attachment()) { if (!$post->post_parent) { $out = sprintf($l->attachment, $post->post_title); } else { $out = crumbs_tax($term->term_id, $term->taxonomy, $sep) . "<a class='subpage_block' href='" . get_permalink($post->post_parent) . "'>" . get_the_title($post->post_parent) . "</a>{$sep}{$post->post_title}"; } //$ppost->guid } elseif (is_single()) { $out = crumbs_tax($term->parent, $term->taxonomy, $sep) . "<a class='subpage_block' href='" . get_term_link((int) $term->term_id, $term->taxonomy) . "'>{$term->name}</a>{$sep}{$post->post_title}"; } elseif (!is_taxonomy_hierarchical($term->taxonomy)) { if (is_tag()) { $out = $pg_term_start . sprintf($l->tag, $term->name) . $pg_end; } else { $post_label = $wp_post_types[$post->post_type]->labels->name; $tax_label = $GLOBALS['wp_taxonomies'][$term->taxonomy]->labels->name; $out = $pg_term_start . sprintf($l->tax_tag, $post_label, $tax_label, $term->name) . $pg_end; } } else { $out = crumbs_tax($term->parent, $term->taxonomy, $sep) . $pg_term_start . $term->name . $pg_end; } } $home = '<a class="subpage_block" href="' . home_url() . '">' . $l->home . '</a>' . $sep; return print $home . $out; }