'; // tag before the current breadcrumb.
$after = ''; // tag after the current breadcrumb.
$home_link = home_url( '/' );
echo '
';
echo '- ' . esc_html__( 'Home', 'bogaty-lite' ) . '
';
if ( is_home() ) {
echo '- ' . get_query_var( 'pagename' ) . '
'; // WPCS: XSS OK.
}
// Handle the category.
if ( is_category() ) {
$this_cat = get_queried_object();
if ( 0 !== $this_cat->parent ) {
$parent = get_category( $this_cat->parent );
$parent_link = get_category_link( $this_cat->parent );
echo '- ' . $parent->name . '
'; // WPCS: XSS OK.
echo $before . $this_cat->name . $after; // WPCS: XSS OK.
} else {
echo $before . $this_cat->name . $after; // WPCS: XSS OK.
}
} elseif ( is_search() ) {
$text = sprintf( 'Search results for %s', get_search_query() );
echo $before . $text . $after; // WPCS: XSS OK.
} elseif ( is_day() ) { // Handle the time.
$year = get_year_link( get_the_time( 'Y' ) );
$month = get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) );
echo '- ' . get_the_time( 'Y' ) . '
'; // WPCS: XSS OK.
echo '- ' . get_the_time( 'F' ) . '
'; // WPCS: XSS OK.
echo $before . get_the_time( 'd' ) . $after; // WPCS: XSS OK.
} elseif ( is_month() ) {
$year = get_year_link( get_the_time( 'Y' ) );
echo '- ' . get_the_time( 'Y' ) . '
'; // WPCS: XSS OK.
echo $before . get_the_time( 'F' ) . $after; // WPCS: XSS OK.
} elseif ( is_year() ) {
echo $before . get_the_time( 'Y' ) . $after; // WPCS: XSS OK.
} elseif ( is_single() ) { // Handle the single with categories.
// Show the name of jetpack post type or another post types, followed by the title of the post of that post type.
if ( ! is_singular( 'post' ) ) {
$post_type = get_post_type_object( get_post_type() );
$post_type_archive_link = get_post_type_archive_link( get_post_type() );
$slug = $post_type->rewrite;
echo '- ' . $post_type->labels->singular_name . '
'; // WPCS: XSS OK.
the_title( $before, $after );
} else {
echo '- ' . get_the_category_list( ', ' ) . '
'; // WPCS: XSS OK.
the_title( $before, $after );
}
} elseif ( is_post_type_archive() ) {
$post_type = get_post_type_object( get_post_type() );
echo $before . $post_type->labels->singular_name . $after; // WPCS: XSS OK.
}
// Handle the page.
$id = get_the_id();
$parent_id = wp_get_post_parent_id( $id );
// Check if page has parent.
if ( is_page() && ! $parent_id ) {
esc_html( the_title( $before, $after ) );
}
// If the page has parent.
if ( is_page() && $parent_id ) {
$breadcrumbs = array();
// Get all the parents of the child page. The page of parent is set in the page not in the menu.
while ( $parent_id ) {
$page = get_post( $parent_id );
$breadcrumbs[] = '- ' . get_the_title( $page->ID ) . '
';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse( $breadcrumbs );
$parent_length = count( $breadcrumbs );
$i = 0;
while ( $i < $parent_length ) {
echo $breadcrumbs[ $i ]; // WPCS: XSS OK.
$i++;
}
the_title( $before, $after );
} elseif ( is_tag() ) {
echo $before . single_tag_title( '', false ) . $after; // WPCS: XSS OK.
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata( $author );
echo $before . $userdata->display_name . $after; // WPCS: XSS OK.
} elseif ( is_404() ) {
echo $before . esc_html__( 'Error 404', 'bogaty-lite' ) . $after; // WPCS: XSS OK.
}
echo '
';
} // End if().
}
} // End if().