full path in breadcrumbs wordpress
I want to take a full path in bread crumbs in the wordpress template
Now displays only the home page and category
I want the home - category - the title of the article with the link to this page, with a working schema markup
now the code looks like this version Wordpress 4.8.1
function barcelona_breadcrumb() {
if ( barcelona_get_option( 'show_breadcrumb' ) != 'on' ) {
return;
}
$barcelona_post_type = is_single() ? get_post_type() : NULL;
$barcelona_sep_icon = '';
$barcelona_items = '';
if ( ( is_single() && $barcelona_post_type == 'post' && ! is_attachment() ) || is_category() ) {
$barcelona_categories = is_category() ? array() : get_the_category();
$barcelona_current_cat = $barcelona_last_cat = is_category() ? get_queried_object() : $barcelona_categories[0];
$barcelona_counter = 3;
while ( $barcelona_current_cat->category_parent != '0' ) {
$barcelona_current_cat = get_category( $barcelona_current_cat->category_parent );
$barcelona_items = $barcelona_sep_icon .'<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="'. esc_url( get_category_link( $barcelona_current_cat ) ) .'"><span itemprop="name">'. esc_html( $barcelona_current_cat->name ) .'</span></a><meta itemprop="position" content="%'. $barcelona_counter .'%" /></li>'. $barcelona_items;
$barcelona_counter++;
}
$barcelona_items .= $barcelona_sep_icon .'<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><'. ( is_category() ? 'span' : 'a href="'. esc_url( get_category_link( $barcelona_last_cat ) ) .'"' ) .' itemprop="item"><span itemprop="name">'. esc_html( $barcelona_last_cat->name ) .'</span></'. ( is_category() ? 'span' : 'a' ) .'><meta itemprop="position" content="%2%" /></li>';
if ( $barcelona_counter > 3 ) {
$barcelona_arr = array_reverse( range( 2, $barcelona_counter - 1 ) );
foreach( $barcelona_arr as $k => $v ) {
$barcelona_items = str_replace( 'itemprop="position" content="%'. intval( $k + 2 ) .'%"', 'itemprop="position" content="'. intval( $v ) .'"', $barcelona_items );
}
} else {
$barcelona_items = str_replace( 'content="%2%"', 'content="2"', $barcelona_items );
}
} else if ( is_archive() || is_search() ) {
$barcelona_title = is_search() ? esc_html__( 'Search Results', 'barcelona' ) : esc_html( get_the_archive_title() );
if ( is_author() ) {
$barcelona_title = esc_html__( 'Author Archive', 'barcelona' );
} else if ( is_year() ) {
$barcelona_title = esc_html__( 'Yearly Archive', 'barcelona' );
} else if ( is_month() ) {
$barcelona_title = esc_html__( 'Monthly Archive', 'barcelona' );
} else if ( is_day() ) {
$barcelona_title = esc_html__( 'Daily Archive', 'barcelona' );
} else if ( is_tag() ) {
$barcelona_title = esc_html__( 'Tag Archive', 'barcelona' );
}
$barcelona_items .= $barcelona_sep_icon .'<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="item"><span itemprop="name">'. $barcelona_title .'</span></span><meta itemprop="position" content="2" /></li>';
}
$barcelona_items = '<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="'. esc_url( home_url( '/' ) ) .'">'. esc_html__( 'Home', 'barcelona' ) .'</a><meta itemprop="position" content="1" /></li>'. $barcelona_items;
echo '<div class="breadcrumb-wrapper"><div class="container"><ol itemscope itemtype="http://schema.org/BreadcrumbList" class="breadcrumb">'. $barcelona_items .'</ol></div></div>';
}
Thanks!
Try with below code put below code in functions.php
function the_breadcrumbs() {
global $post;
if (!is_home()) {
echo "<a href='";
echo get_option('home');
echo "'>";
echo "Site's name here";
echo "</a>";
if (is_category() || is_single()) {
echo " > ";
$cats = get_the_category( $post->ID );
foreach ( $cats as $cat ){
echo $cat->cat_name;
echo " > ";
}
if (is_single()) {
the_title();
}
} elseif (is_page()) {
if($post->post_parent){
$anc = get_post_ancestors( $post->ID );
$anc_link = get_page_link( $post->post_parent );
foreach ( $anc as $ancestor ) {
$output = " > <a href=".$anc_link.">".get_the_title($ancestor)."</a> > ";
}
echo $output;
the_title();
} else {
echo ' > ';
echo the_title();
}
}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"Archive: "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"Archive: "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"Archive: "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"Author's archive: "; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "Blogarchive: "; echo'';}
elseif (is_search()) {echo"Search results: "; }
}
Put below code in header.php
if(function_exists('the_breadcrumbs')) the_breadcrumbs();
链接地址: http://www.djcxy.com/p/6666.html