RP_Rave1_theme/template-parts/breadcrumbs.php
Virág Gábor 4664ef511d upload
2024-11-06 11:10:48 +01:00

74 lines
No EOL
2.7 KiB
PHP

<?php
/* Breadcrumbs */
function get_breadcrumb()
{
global $post;
$separator = ' - ';
$home_title = 'Kezdőoldal';
// Megvizsgálja, hogy az adott oldal a Kezdőoldal-e
if (is_front_page()) {
return; // Amennyiben a kezdőoldal, akkor nincs breadcrumb
}
// Start the breadcrumb with a link to your homepage
echo '<div class="breadcrumb">';
echo '<span><a href="' . get_home_url() . '">' . $home_title . '</a></span>';
if (is_archive() && !is_tax() && !is_category() && !is_tag()) {
echo '<span>' . post_type_archive_title('', false) . '</span>';
} elseif (is_single()) {
$post_type = get_post_type();
if ($post_type != 'post') {
$post_type_object = get_post_type_object($post_type);
$post_type_archive = get_post_type_archive_link($post_type);
echo '<span><a href="' . $post_type_archive . '">' . $post_type_object->labels->name . '</a></span>' . $separator;
}
$category = get_the_category();
if (!empty($category)) {
$last_category = end(array_values($category));
$cat_parents = rtrim(get_category_parents($last_category->term_id, true, $separator), $separator);
echo '<span>' . $cat_parents . '</span>';
}
echo '<span>' . get_the_title() . '</span>';
} elseif (is_page()) {
if ($post->post_parent) {
$ancestors = array_reverse(get_post_ancestors($post->ID));
foreach ($ancestors as $ancestor) {
echo '<span><a href="' . get_permalink($ancestor) . '">' . get_the_title($ancestor) . '</a></span>' . $separator;
}
}
echo '<span>' . get_the_title() . '</span>';
} elseif (is_category()) {
echo '<span>' . single_cat_title('', false) . '</span>';
} elseif (is_tag()) {
echo '<span>' . single_tag_title('', false) . '</span>';
} elseif (is_day()) {
echo '<span><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a></span>' . $separator;
echo '<span><a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a></span>' . $separator;
echo '<span>' . get_the_time('d') . '</span>';
} elseif (is_month()) {
echo '<span><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a></span>' . $separator;
echo '<span>' . get_the_time('F') . '</span>';
} elseif (is_year()) {
echo '<span>' . get_the_time('Y') . '</span>';
} elseif (is_author()) {
$userdata = get_userdata(get_query_var('author'));
echo '<span>' . 'Author: ' . $userdata->display_name . '</span>';
} elseif (get_query_var('paged')) {
echo '<span>' . 'Page ' . get_query_var('paged') . '</span>';
} elseif (is_search()) {
echo '<span>' . 'Search results for: ' . get_search_query() . '</span>';
} elseif (is_404()) {
echo '<span>' . 'Error 404' . '</span>';
}
echo '</div>';
}
?>