add files
This commit is contained in:
43
template-parts/breadcrumbs.php
Normal file
43
template-parts/breadcrumbs.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
if ( ! is_single() ) return;
|
||||
|
||||
// Рекурсивная функция с Schema.org позицией
|
||||
function render_full_category_breadcrumbs( $cat_id, &$position = 1, $separator = ' > ' ) {
|
||||
$cat = get_category( $cat_id );
|
||||
if ( ! $cat ) return;
|
||||
|
||||
// Рекурсивно выводим родителей
|
||||
if ( $cat->parent != 0 ) {
|
||||
render_full_category_breadcrumbs( $cat->parent, $position, $separator );
|
||||
}
|
||||
|
||||
// Выводим категорию с Schema.org структурой
|
||||
echo '<li property="itemListElement" typeof="ListItem" itemprop="itemListElement">
|
||||
<a property="item" typeof="WebPage" href="' . esc_url( get_category_link( $cat->term_id ) ) . '">
|
||||
<span property="name" itemprop="name">' . esc_html( $cat->name ) . '</span>
|
||||
</a>
|
||||
<meta property="position" content="' . $position . '" />
|
||||
</li>';
|
||||
|
||||
$position++;
|
||||
}
|
||||
|
||||
$categories = get_the_category();
|
||||
if ( empty( $categories ) ) return;
|
||||
|
||||
$main_cat = $categories[0];
|
||||
$breadcrumb_position = 1;
|
||||
?>
|
||||
|
||||
<nav class="breadcrumbs" aria-label="Навигация по рубрикам" itemscope itemtype="https://schema.org/BreadcrumbList">
|
||||
<ol class="breadcrumbs_list" itemprop="itemListElement">
|
||||
<?php render_full_category_breadcrumbs( $main_cat->term_id, $breadcrumb_position ); ?>
|
||||
<li property="itemListElement" typeof="ListItem">
|
||||
<span property="item" typeof="WebPage" itemprop="name"><?php the_time('j F Y, H:i \М\С\К'); ?></span>
|
||||
<meta property="position" content="<?php echo ++$breadcrumb_position; ?>" />
|
||||
</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user